166k views
25 votes
Copy the skeleton of code below into your answer. Then in the space indicated, add your own code to prompt the user for two numbers and a string and then prints the difference of those numbers with a message to the user (text in bold is input entered by the user). Note that the final output should be on a line by itself. Recall that the difference of two numbers is found by subtracting the second number from the first.

Enter the first: 10
Enter the second: 3
Enter your name: Dinah Drake
Dinah Drake, the difference is 7

User Fycth
by
3.4k points

1 Answer

3 votes

Answer:

import java.util.*;

public class Main

{

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

System.out.print("Enter the first: ");

int first = input.nextInt();

System.out.print("Enter the second: ");

int second = input.nextInt();

input.nextLine();

System.out.print("Enter your name: ");

String name = input.nextLine();

int difference = Math.abs(second - first);

System.out.println(name + ", the difference is " + difference);

}

}

Step-by-step explanation:

*The code is in Java.

Create a Scanner object to get input from the user

Ask the user to enter the first, second, and name

Calculate the difference, subtract the second from the first and then get the absolute value of the result by using Math.abs() method

Print the name and the difference as in required format

User Hikalkan
by
3.0k points