I am simply trying to add numbers from 1 to Integer.MAX_VALUE, but in output I'm getting nothing. The program is struck in between. Below is the class that I created.
public class Test {
public static void main(String args[]) {
long sum = 0;
int start_value = 1;
long end_value = Integer.MAX_VALUE;
while(start_value <= end_value){
sum += start_value;
start_value++;
}
System.out.println(sum);
}
}
Do anybody have any idea why this is hanging. This program is never completed.
How to solve this type of problem?
int start_value = 1;tolong start_value = 1;.