Question

Write a java program that asks the user to enter 2 integers, obtains them from the...

Write a java program that asks the user to enter 2 integers, obtains them from the user, determines if they are even or odd numbers and prints their sum, product, difference, and quotient (Division).

0 1
Add a comment Improve this question Transcribed image text
Answer #1

Code::

import java.util.*;

class Sum

{

public static void main(String args[])

{

int a, b;

Scanner sc = new Scanner(System.in);

System.out.println("Enter the first integer");

a = sc.nextInt(); //input first integer from user

System.out.println("Enter the second integer");

b = sc.nextInt(); //input second integer from user

//Check if a is odd or even

if(a%2==0)

System.out.println(a+" is even number");

else

System.out.println(a+" is odd number");

//Check if b is odd or even

if(b%2==0)

System.out.println(b+" is even number");

else

System.out.println(b+" is odd number");

//Calculate sum

System.out.println("Sum = "+(a+b));

//Calculate product

System.out.println("Product = "+(a*b));

//Calculate difference

System.out.println("Difference = "+(a-b));

//Calculate quotient

System.out.println("Quotient = "+(a/b));

}

}

Code Screenshot::

import java.util.*; class Sum public static void main(String args[]) int a, b; Scanner sc = new Scanner(System.in); System.ou

Output::

H:locpjp test javac Sum.java H: ocpjp test>java Sum Enter the first integen Enter the second integer 5 is odd number 8 is eve

If you have any doubt, please feel free to ask.

Thank you.

Add a comment
Know the answer?
Add Answer to:
Write a java program that asks the user to enter 2 integers, obtains them from the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write an application that asks the user to enter two integers, obtains them from the user...

    Write an application that asks the user to enter two integers, obtains them from the user and prints their sum, product, difference and quotient (division).(i.e. Scanner, nextInt and printf) (this has to be in java) Enter·first·integer:31 ·Enter·second·integer:69 ·31+69=100 31*69=2139 31-69=-38 31/69=0

  • Write a C++ program that does the following: Asks the user to enter 3 integers, Obtains...

    Write a C++ program that does the following: Asks the user to enter 3 integers, Obtains the numbers from the user, Prints the largest number and then the smallest of the numbers, If the numbers are equal, prints the message: "These numbers are equal." Prints the sum, average, and product of the 3 numbers.

  • 1. Write a program that asks the user to enter two integers, obtains the numbers from...

    1. Write a program that asks the user to enter two integers, obtains the numbers from the user, then prints the larger number followed by the words “is larger.” If the numbers are equal, print the message “These numbers are equal.” Use only the single-selection form of the if statement you learned in this chapter.

  • Write a Java program that: • Asks the user to enter the number of integers that...

    Write a Java program that: • Asks the user to enter the number of integers that he need to enter; • Asked him to enter integer by integer; • Print The number of Odd numbers entered and the number of Even numbers entered. Important notes: 1. You should have to copy and paste the Java as your answer for this question. DON’T take screen shot for your Java Code. It must be editable. 2. Take a screen shot for your...

  • Write a C++ program that asks the user to enter a single number from 1 to...

    Write a C++ program that asks the user to enter a single number from 1 to 50 and a choice of "even" or "odd". Using a recursive function, output the sum of all the even or odd integers from 1 up to (and including) that number. Your program does not need to loop and accept more input (only one input of the number then even/odd).

  • IN PYTHON write a program that asks the user to enter 10 numbers and store them...

    IN PYTHON write a program that asks the user to enter 10 numbers and store them in the list and then find the followings: • Maximum • Minimum prime numbers in the list • even numbers in the list • odd numbers in the list.

  • C++ Write a program that prompts the user to enter integers or a sentinel to stop....

    C++ Write a program that prompts the user to enter integers or a sentinel to stop. The program prints the highest and lowest numbers entered, the sum and the average. DO NOT USE ARRAYS, only variables and loops. Write a program the prompts the user to input a positive integer. Keep asking the user until a positive integer is entered. Once a positive integer is entered, print a message if the integer is prime or not. (NOTE: A number is...

  • Q1. Write a program in Java         a. Create 2 separate arrays, of user defined values,...

    Q1. Write a program in Java         a. Create 2 separate arrays, of user defined values, of same size         b. Add these 2 arrays. ........................................................................................................................... Q2. Write a program in java (using loop) input any10 numbers from user and store in an array. Check whether each of array element is positive, negative, zero, odd or even number. ............................................................................................................................ Q3. Write a program in Java to display first 10 natural numbers. Find the sum of only odd numbers. .............................................................................................................................. Q4....

  • Write a Java program which allows the user to perform simple tasks on a calculator. A...

    Write a Java program which allows the user to perform simple tasks on a calculator. A series of methods allows the user to select an operation to perform and then enter operands. The first method displays a menu, giving the user the choice of typing in any one of the following: +, -, *, /, or % representing the usual arithmetic operators (Each operation should be done on numbers negative(-) to positive(+), positive(+) to negative(-), negative(-) to negative(-), and positive(+)...

  • Write a complete java program that prompts the user for their name and two numbers. The...

    Write a complete java program that prompts the user for their name and two numbers. The correct java methods and parameters must be passed to find the length of the name entered and return “TRUE” if the sum of numbers is even, or FALSE if the sum of numbers is odd: Notes included in the program Sample Program Please enter a name and I will tell you the length of the name entered John Then length of the name John...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT