import java.util.Scanner; public class test { public static void main (String[] args) { Scanner scan = new Scanner(System.in); System.out.println("Enter numbers: "); int num = scan.nextInt(); int numbers = 5; int array[] = new int [numbers]; int numCount = 0; while (numCount < numbers) { array[numCount++]=scan.nextInt(); } for(int i:array){ System.out.println(i); } } }
I'm trying to do two things, make it accept only positive numbers from user,
and also to terminate if the user enters 0
And also when I enter like the numbers 1,2,3,4,5,6
in a row it omits the first 1 I enter, and only stores the number 2,3,4,5,6
Any help would be appreciated