Graderpractice for programmers

254271 Fundamentals Programming - while (sc.hasNext())

Awaiting submission
Write a program that reads integers and prints out their value plus one. Stop reading input when the input is -1.

Use the following code:

Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
   int x = sc.nextInt();
   if (x == -1) {
      break;
   }
   // your code here...
}
Awaiting submission
Write a program that inputs a list of numbers and returns the mean (to 1 decimal place). The end of the input is -1.

Hint: to print a float/double with 1 d.p. precision then use String.format(...)

double x = 1.23456;
System.out.println(String.format("%.1f", x));
Awaiting submission
Write a program that inputs a list of numbers and returns the mean (to 1 decimal place). The end of the input is when the user presses Ctrl-Z.