Can any1 help me to write a code to make output as a picture? thank you Sum and
ID: 3542058 • Letter: C
Question
Can any1 help me to write a code to make output as a picture?
thank you
Sum and Multiplication Calculator Enter two whole numbers: 2 8 Enter add to sum the even numbers from the first to the second or multiply to find the product of the two numbers: add The sum of the even numbers from the first to the second is 20 Do you want to get two numbers, y or n? y Enter two whole numbers: 5 6 Enter add to sum the even numbers from the first to the second or multiply to find the product of the two numbers: multiply The product of the two numbers is 30 Do you want to get two numbers, y or n? y Enter two whole numbers: 5 10 Enter add to sum the even numbers from the first to the second or multiply to find the product of the two numbers: add The first number must be even and less than or equal to the second number. Please enter two more numbers: 6 1( The sum of the even numbers from the first to the second is 2 4 Do you want to get two numbers, y or n? y Enter two whole numbers: 10 6 Enter add to sum the even numbers from the first to the second or multiply to find the product of the two numbers: add The first number must be even and less than or equal to the second number. Please enter two more numbers: 4 1 The sum of the even numbers from the first to the second is 40 Do you want to get two numbers, y or n? nExplanation / Answer
import java.util.*;
import java.lang.*;
import java.io.*;
class calculator
{
public static void main(String[] args)
{
int num1,num2;
char response = 'y';
String ans;
Scanner in = new Scanner(System.in);
while(response=='y' || response=='Y')
{
System.out.println("Enter two whole numbers :");
num1 = in.nextInt();
num2 = in.nextInt();
System.out.println("Enter add to sum the even numbers from first to the second or multiply to find the product of two numbers");
ans = in.next();
if(ans.equalsIgnoreCase("add"))
{
while(num1%2!=0 || num2%2!=0 || num1 > num2)
{
System.out.println("First number must be even and less than or equal to second number");
System.out.println("Please enter two more numbers :");
num1 = in.nextInt();
num2 = in.nextInt();
}
int sum =0;
for(int i=num1; i<=num2; i+=2)
sum = sum + i;
System.out.println("The sum of even numbers from first to second is "+ sum);
}
else if(ans.equalsIgnoreCase("multiply"))
System.out.println("The product of the two numbers is "+ num1*num2);
System.out.println("do you want to get two numbers, y or n ? ");
response = in.next().charAt(0);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.