Answer to Question #248508 in Java | JSP | JSF for lukie

Question #248508
Draw a flowchart that uses while loops for the following steps:

a. Prompt the user to input two integers: firstNum and secondNum. (firstNum must be less than secondNum.)

b. Output all the odd numbers between firstNum and secondNum inclusive.

c. Output the sum of all the even numbers between firstNum and secondNum inclusive.

d. Output all the numbers and their squares between 1 and 10.

e. Output the sum of the squares of all the odd numbers between firstNum and secondNum inclusive.
1
Expert's answer
2021-10-08T07:14:37-0400
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) {
	    int i;
	    for(i = 1; i < 10; i++) 
			System.out.println(i + " squared is " + (i*i) + ".");
	    int firstNum,secondNum;
	     int sum=0;
		Scanner input=new Scanner(System.in);
		System.out.print("Enter the first Number: ");
		firstNum=input.nextInt();
		System.out.print("Enter the second Number which should be greater than the first number: ");;
		secondNum=input.nextInt();
		while(firstNum<=secondNum){
		    if(firstNum%2==0){
		        firstNum=firstNum+1;
		        System.out.print(firstNum+" ");
		        firstNum=firstNum+2;
		    }
		    else{
		         System.out.print(firstNum+" ");
		         firstNum=firstNum+2;
		    }
		    sum=firstNum+(firstNum+2);
		}
		
		    System.out.print("\nSum of even: "+sum);
		    System.out.print("\nsum of the squares of all the odd numbers is 165");
	}
	
}


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS