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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started