Draw a flowchart that uses while loops to perform 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.
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");
}
}
Comments
Leave a comment