It's not a secret anymore!
The moose likes Beginning Java and the fly likes problem in loop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "problem in loop" Watch "problem in loop" New topic

problem in loop

Siddhesh Desai

Joined: Jun 28, 2004
Posts: 9
i am just doing one simple program in that i am giving input from console but it gives me random output.please help me
thanks in advance
the code is :::
import java.util.*;
import java.lang.*;

class Array
public static void main(String args[])
throws IOException
int number;
BufferedReader br = new BufferedReader(new InputStreamReader(;
int array[]=new int[10];
for(int i=0;i<=2;i++)
number = (int);
for(int i=0;i<10;i++)
System.out.print(array[i]+" ");
System.out.println(" ");

it will give random output
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24193


Welcome to JavaRanch!

Not sure what you mean by "random output," but note that this program will print the character codes of the characters you type in -- not the interpretation of those codes as textual integers. The number "48" is the character code for 0; 49 is 1; etc.

The proper way to write your program is to read Strings, then use the static Integer.parseInt() method to interpret those strings. See Sun's I/O tutorial at .

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: problem in loop
It's not a secret anymore!