Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write this program Lab Assignment: Write an application that prompts the iiser f

ID: 3549806 • Letter: W

Question

write this program


Lab Assignment: Write an application that prompts the iiser for-two integers.Uje the variable names firs{Num and secondNum^ Make sure firstNum is less than secondflum y switch them if necessary.Then, create separate loops to output each of the following which :Using a while loop, output all the even numbers from firstNum and secondNum Using a do..while loop, output the sum of the odd numbers between firstNum and "secondNum. For this loop, you will need a variable like 'total' to hold the answer as it is being constructed.Using a for loop, output all the numbers, the_square of the numbers, and the cube of the numbers between 41 and 83 in increments of 4. The square of a number is the number times itself. (Example: the square of 4 is 4 4). The cube of a number is the number times itself and then times itself again. (Example: the cube of 3 is 3 3 * 3).Using any loop structure you like, output the sum of the squares of all the even numbers between firstNum and secondNum.Using any loop structure you like, print all the uppercase letters where the initial letter is 'A' and the loop manipulates the initial letter to produce each subsequent letter, (ie. You can not print each letter individually -they must be generated)For each of these steps, you must: Ensure that the initial value of first Num and secondNum are not changed. Re-use any previously declared and used variables whenever

Explanation / Answer

import java.util.Scanner;



public class NumberCalc {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.println("Enter first number");

int firstNum = sc.nextInt();

System.out.println("enter second number9");

int secondNum = sc.nextInt();

// output all even from firstNum to secondNum

int i = firstNum;

while(i<=secondNum){

if(i%2==0){

System.out.print(i+" ");

}

i++;

}

System.out.println("");

//sum of odd number between firstNum and secondNum

i = firstNum;

int sum = 0;

do{

if(i%2!=0){

sum = sum +i;

}

i++;

}while(i<=secondNum);

System.out.println("Sum of odd number between firstnum and secondnum is "+sum);

//output square and cube of number between 41 and 83 in increment 4

for(int j=41;j<=83;j+=4){

System.out.println("Square of"+ j +" is "+(j*j)+" cube of "+j+" is "+(j*j*j));

}

//sum of square of numbers between firstNum and secondNum

i = firstNum;

sum =0;

while(i<=secondNum){

if(i%2==0){

sum = sum + (i*i);

}

i++;

}

System.out.println("the sum of square of even number is: "+sum);

//printing uppercase

i = 65;

while(i<=90){

char ch = (char)i;

System.out.print(ch+" ");

i++;

}

}

}