Thread: Java Error
View Single Post
  #2 (permalink)  
Old 09-04-2007, 10:50 PM
HelloWorld's Avatar
HelloWorld HelloWorld is offline
PT Admin
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: In front of computer...
Posts: 1,118
iTrader: (0)
HelloWorld is a jewel in the roughHelloWorld is a jewel in the roughHelloWorld is a jewel in the rough
How do you want to read the input from the user? Is it from the command line? From a file or what? If it's a command line input, I'd suggest you to just use Scanner class... It's the same thing, but it's make your code looks nicer lol...

and then use this method:

Quote:
String nextLine()
Advances this scanner past the current line and returns the input that was skipped.
Code:
import java.util.Scanner;

public class Test {
  public static void main(String[] args) {
    Scanner s = new Scanner();
    int[] num = new int[10];
    int cnt = 0;
    while (cnt < num.length) {
      System.out.print("Enter number: ");
      String number = s.nextLine();
      int[cnt] = Integer.parseInt(number); // you need to add try.. catch.. block
      System.out.println(int[cnt]);
    }
  }
}
let me know if it works lol.. I didn't test it

__________________
PHP Code:
System.out.println("Hello World!"); 

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!

Last edited by HelloWorld : 09-04-2007 at 10:56 PM.
Reply With Quote
The Following User Says Thank You to HelloWorld For This Useful Post:
TeraTask (09-05-2007)