Reading from Keyboard to an Array    P.Komisar



 

import java.io.*;

public class MoreX{
public static void main(String[]args){
   int i=0;
   byte[] c =new byte[20];     // input to an array rather than a byte
 try{
      while(i != -1){
         i = System.in.read(c);    // now the return type is an int saying how many bytes read
         System.out.println(i);
         }
     }                                      // exit the loop with Ctrl Z which enters -1
     catch(IOException io){
     System.out.println("IO");
     }

for(int j=0;j<c.length;j++)       // outputing to screen what was input into the array
   System.out.print((char)c[j] + "   " + c[j] +"\n");
   }
 }