I have this really simple code:
public class ArrayIO {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number from 50 to 150: ");
int elements = sc.nextInt();
while(elements<50 && elements>150) {
System.out.println("Less than 50 or more than 150");
elements = sc.nextInt();
}
sc.close();
ArrayList<Integer> integers = new ArrayList<>();
for(int i=1; i<=elements; i++) {
integers.add(i);
}
integers.toArray();
System.out.printf("Array size is %d\n", integers.size());
}
}
but my program bypasses the while loop completely when it has more than one condition. It works just fine with only one condition. I feel like I'm doing some really stupid mistake, but I just can't quite get it for almost an hour already.
||(Two pipes)System.out.println("Enter a number from 50 to 150: ");you may want :while( elements >= 50 && elements <= 150 )