write this program Lab Assignment: Write an application that prompts the iiser f
ID: 3549806 • Letter: W
Question
write this program
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++;
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.