natetheman7740
29.11.2020 •
Computers and Technology
Simple Arithmetic Program
Using the instructions from Week 1 Lab, create a new folder named Project01. In this folder create a new class named Project01. This class must be in the default package. Make sure that in the comments at the top of the Java program you put your name and today's date using the format for Java comments given in the Week 1 Lab.
For this lab, you will write a Java program to prompt the user to enter two integers. Your program will display a series of arithmetic operations using those two integers. Create a new Java program named Project01.java for this problem.
Sample Output: This is a sample transcript of what your program should do. Items in bold are user input and should not be put on the screen by your program. Make sure your output looks EXACTLY like the output below, including spacing. Items in bold are elements input by the user, not hard-coded into the program.
Enter the first number: 12
Enter the second number: 3
12 + 3 = 15
12 - 3 = 9
12 * 3 = 36
12 / 3 = 4
12 % 3 = 0
The average of your two numbers is: 7
A second run of your program with different inputs might look like this:
Enter the first number: -4
Enter the second number: 3
-4 + 3 = -1
-4 - 3 = -7
-4 * 3 = -12
-4 / 3 = -1
-4 % 3 = -1
The average of your two numbers is: 0
HINT: You can start by retyping the code that was given to you in Exercise 3 of ClosedLab01. That code takes in a single number and performs a few arithmetic operations on it. How can you modify that code to take in two numbers? How can you modify it to display "number * number =" instead of "Your number squared is: "? Take it step by step and change one thing at a time.
You can use the following as a template to get you started. Note that you must create your class in the default package and your project must be named Project01.java for the autograder to be able to test it when you submit it.
Solved
Show answers
More tips
- H Health and Medicine Simple and Effective: How to Get Rid of Cracked Heels...
- L Leisure and Entertainment What to Bring on a Hike? Essential Items to Pack for a Safe and Enjoyable Adventure...
- L Leisure and Entertainment Couchsurfing: A New Way to Travel...
- S Style and Beauty Autotanning: Harmful or Safe?...
- F Food and Cooking 10 Ideas for a Wedding Anniversary Gift...
- H Health and Medicine How to Reduce Sweating in the Heat and Beyond: Say Goodbye to Excessive Sweat...
- F Food and Cooking Do Aphrodisiacs Really Work? Separating Fact from Fiction...
- H Health and Medicine What to Eat to Lose Weight?...
- A Animals and plants How to Teach Your Parrot to Talk?...
- H Health and Medicine How to Improve Your Posture?...
Answers on questions: Computers and Technology
- M Mathematics 2(a - 4) + 15 = 13 Please help...
- M Mathematics How does the b value transform the graph of a sine function? A. Stretches or compresses the graph horizontally, changing the period and frequency of the graph B. Shifts the...
- M Mathematics Find the values of A and B in each triangle Show your work...
- E English Free pointss :( come take guys...
- M Mathematics 12g + 21 and 3(4g + 7) Is it equivalent?...
- H Health Select the correct answer. Nafisa’s job involves taking X-rays of patients who have suffered fractured bones due to accidents. Many of them feel nervous when taking the X-ray....
- M Mathematics If g(x)=x+7 translated down 3 units...
- C Computers and Technology What types of files we do backup in UNIX and Linux?...
- M Mathematics What is 2y - 1/6x = 3/4 in Standard Form?...
- C Chemistry JOIN MY MEETINGID-9384026088PASSWORD 1234 ...
Ответ:
Written in Java
import java.util.*;
public class Project01{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int num1,num2;
System.out.print("Enter first number: ");
num1 = input.nextInt();
System.out.print("Enter second number: ");
num2 = input.nextInt();
System.out.println(num1+" + "+num2+" = "+(num1 + num2));
System.out.println(num1+" - "+num2+" = "+(num1 - num2));
System.out.println(num1+" * "+num2+" = "+(num1 * num2));
System.out.println(num1+" / "+num2+" = "+(num1 / num2));
System.out.print("The average of your two numbers is: "+(num1 + num2)/2);
}
}
Explanation:
import java.util.*;
public class Project01 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
This line declares myfirstnum and mysecnum as integer
int myfirstnum,mysecnum;
This line prompts user for first number
System.out.print("Enter first number: ");
This line gets user input
myfirstnum= input.nextInt();
This line prompts user for second number
System.out.print("Enter second number: ");
This line gets user input
mysecnum = input.nextInt();
This line calculates and prints addition operation
System.out.println(myfirstnum+" + "+mysecnum+" = "+(myfirstnum + mysecnum));
This line calculates and prints subtraction operation
System.out.println(myfirstnum+" - "+mysecnum+" = "+(myfirstnum - mysecnum));
This line calculates and prints multiplication operation
System.out.println(myfirstnum+" * "+mysecnum+" = "+(myfirstnum * mysecnum));
This line calculates and prints division operation
System.out.println(myfirstnum+" / "+mysecnum+" = "+(myfirstnum / mysecnum));
This line calculates and prints the average of the two numbers
System.out.print("The average of your two numbers is: "+(myfirstnum + mysecnum)/2);
}
}
Ответ:
A. it provides the browser with information about the webpage