import java.util.Scanner;
public class test {
public static void main(String args[]){
int a = 1000;
while(a>0){
System.out.println("Question to prevent infinite while loop");
Scanner input = new Scanner (System.in);
int inzet = input.nextInt();
System.out.println(a);
test(a);
}
}
public static void test(int a){
System.out.println(a);
a = a + 100;
System.out.println(a);
}
}
I have a question. Why does int a
not update? It resets to 1000 every time. I don't want that. Can someone please help me? If I run the program I get this:
Question to prevent infinite while loop
2
1000
1000
1100
Question to prevent infinite while loop
2
1000
1000
1100
Question to prevent infinite while loop
2
1000
1000
1100
I want to get this code:
Question to prevent infinite while loop
2
1000
1000
1100
Question to prevent infinite while loop
2
1100
1100
1200
Question to prevent infinite while loop
2
1200
1200
1300
Also, this is my first post ever. Please give me some feedback about how I can ask my question better next time.