Need help with this question: Write Java code which reads numbers from the keyboard.....

Posted by Chris on Stack Overflow See other posts from Stack Overflow or by Chris
Published on 2010-05-15T15:49:20Z Indexed on 2010/05/15 15:54 UTC
Read the original article Hit count: 116

Filed under:
|
|
|

Write Java code which reads numbers from the keyboard until zero is entered. Only the positive numbers entered are to be added to a variable-sized collection.

This is what I have so far:

import java.lang.*;
import java.util.*;
import java.io.*;
import java.net.*;

public class Demo1App extends Object
{
 public static void main(String[] argStrings) throws Exception
 {
  ArrayList myArrayList = new ArrayList();
  Scanner input = new Scanner(System.in);
  System.out.println ("NUMBERS:");

  while (int input > 0)
  {
   myArrayList.add(input);
  }

  while (int input < 0)
  {
   System.out.println ("ENTER NUMBERS GREATER THAN 0!");
  }

 }
}

This code doesn't work, I'm not sure why but any help with it would be appreciated.

© Stack Overflow or respective owner

Related posts about java

Related posts about while