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


Write a Java code that reads the number from the keyboard until the zeros are entered. Only the positive numbers entered are added to the variable-size archive.

I still have this:

  import java.lang *; Import java.util. *; Import java.io * *; Import Java.net *; Public class extends Demo1App object {Public static zero main (string [] argstrings throws exceptions {ArrayList myArrayList = new ArrayList (); Scanner input = new scanner (System.in); System.out.println ("number:"); While (int input gt; 0) {myArrayList.add (input); } While (int input <0) {System.out.println ("enter more than"!); }}}  

This code is not working, I'm not sure why any help with this will be appreciated.

You must call the scanner to get the input clearly: scanner.getInt () and This will give you the next integer. You can then try to see if the integer is positive or not


Comments