Question: JAVA would like to know how to a statement within that for loop that does not declare a variable or modify a control variable int
JAVA would like to know how to a statement within that for loop that does not declare a variable or modify a control variable int number = 2 * i + 1; int sum = 0; //prompt message to enter in value for n System.out.println(Please enter in a positive integer); n = input.nextInt(); cleanUpStr = input.nextLine(); //while loop to validate positive number while(n < 0) { System.out.println(Please enter a positive value); n = input.nextInt(); cleanUpStr = input.nextLine(); }//end while loop //for loop used to compute the sum of odd numbers for(i = 0; i < n; i++) { //calculate the numbers int number = 2 * i + 1; System.out.println(number); sum+= number; } //display sum System.out.println(The sum is +sum);
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
