I run the program and all I see is white space below Netbeans.
At first I thought it did not run then I ran four of the programs by accident and Netbeans crashed. So my first question: is it an infinite loop, and if so why?
From what I can see it is int = 0, 0 is >=0 So it should run as 0 + 0… wait if int number and int sum are both zero then does that mean the program can’t proceed because it is stuck with looping zeros? But why wouldn’t it show the output of 0 many times instead of being blank?
public static void main(String[] args) {
int number = 0;
int sum = 0;
while (number >= 0 || number <= 10) {
sum += number;
number += 3;
System.out.print(" Sum is " + sum);
}
}
Think through the logic yourself. When will the number ever not be greater than or equal to 0? You know you have an or operator (
||), and you know that it will be true if either statement on the right or left are true. Maybe you want to use a different operator there?Again think through the logic as it won’t lie to you. In fact you should walk through your code with a pencil and paper starting with 0, and seeing what happens on paper as this will show you your error.