• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

reading array by console

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

i have tried to wrote a class in which i tried to get input from user to populate an array but it results strange
class is
import java.io.*;
class arrayByConsole {
public static void main(String[] args) throws IOException {
BufferedInputStream bis =new BufferedInputStream(System.in);
int myValue=0;
byte[] Array =new byte[8];
System.out.println("Enter number and '10' to exit:");
do
{
Array[myValue]=(byte)bis.read();
myValue=myValue+1;
if (myValue>Array.length)
break;
}
while (Array[myValue-1]!=10);
for (int i=0;i<Array.length;i++){>
System.out.println(Array[i]);
}
}
}
Result is
Enter number and '10' to exit:
233410
50
51
51
52
49
48
13
10
Press any key to continue . . .
any comments and help will be appriciated
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Gul,
What you're seeing is the ASCII values for the digits '2,3,3,4,1,0' and CR and LF.
If you modify the code slightly you can see what's happening:

The output is:

Elements 6 and 7 do not appear as characters.
Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
[This message has been edited by Jane Griscti (edited February 20, 2001).]
reply
    Bookmark Topic Watch Topic
  • New Topic