Hi just started learing
java and I need some help
Here is the Q:
Write a method getSum which has an integer parameter,
which calculates and returns the sum of all numbers from 1 up to and including the value of the integer parameter.
Below is an example of dialogue when running a program that calls this method:
Enter the upper limit: 100
Sum up to 100 is 5050
_______________________
this can be done with thid code:
int answer = sum(100);
System.out.println("Sum up to 100 is " + answer);
}
public static int sum(int n) {
return (n + 1) * n / 2;
}
}
But here I must change the num 100 manualy to get another answer, so I looking for a way to do this with use of java.util.Scanner so I just can write f.ex
Enter the upper limit: 350
Sum up to 350 is 61425
Cheers