1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Troyanec [42]
2 years ago
8

Copy the skeleton of code below into your answer. Then in the space indicated, add your own code to prompt the user for two numb

ers 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
Computers and Technology
1 answer:
ahrayia [7]2 years ago
7 0

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);

}

}

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

You might be interested in
We are building a word processor and we would like to implement a "reflow" functionality that full-justifies text.Given a maximu
adoni [48]

Answer:

The code is given below in Java with appropriate comments

Explanation:

Reflow is an function which helps you to justify your functionality

You need to input a string array and the max width and you will get the

output in a list(string).

public List<String> Reflow(String[] input, int width) {

   List<String> result = new ArrayList<String>();

 

   if(input==null || input.length==0){

       return result;

   }

 

 

   int count=0;

   int last=0;

   ArrayList<String> list = new ArrayList<String>();

   for(int i=0; i<input.length; i++){

       count = count + input[i].length();

 

       if(count+i-last>width){

           int wl = count-input[i].length();

           int sl = maxWidth-wl;

           int each = 1;

           int el = 0;

 

           if(i-last-1>0){

               each = sl/(i-last-1);

               el = sl%(i-last-1);

           }

 

           StringBuilder sb = new StringBuilder();

 

           for(int k=last; k<i-1; k++){

               sb.append(input[k]);

 

               int ce = 0;

               while(ce<each){

                   sb.append(" ");

                   ce++;

               }

 

               if(el>0){

                   sb.append(" ");

                   el--;

               }

           }

 

           sb.append(input[i-1]);//last input in the line

           //if only one word in this line, need to fill left with space

           while(sb.length()<width){

               sb.append(" ");

           }

 

           result.add(sb.toString());

 

           last = i;

           count=input[i].length();

       }

   }

 

   int lastLen = 0;

   StringBuilder sb = new StringBuilder();

 

   for(int i=last; i<input.length-1; i++){

       count = count+input[i].length();

       sb.append(input[i]+" ");

   }

 

   sb.append(input[input.length-1]);

   int d=0;

   while(sb.length()<maxWidth){

       sb.append(" ");

   }

   result.add(sb.toString());

 

   return result;

}

6 0
3 years ago
(Java) Write a program that accepts a number of minutes and converts it both to hours and days. For example, 6000 minutes is 100
iogann1982 [59]
Import java.util.Scanner;
public class MinutesConversion {
private static Scanner inputDevice;
public static void main(String[] args) {
int minutes, hours;
float days; // float for decimal point

inputDevice = new Scanner(System.in);
System.out.println("Please enter minutes for conversion >> ");
minutes = inputDevice.nextInt();
hours = minutes / 60;
days = hours / 24.0f;


System.out.println(+ minutes + " minutes is " + hours + " hour(s) or" + days " days");
}
}
6 0
2 years ago
I will give brainliest!!!!! I NEED HELP ASAP!!!!!!!
klemol [59]

Answer:

I'm pretty sure it's the first answer.

4 0
2 years ago
Which of these has an onboard key generator and key storage facility, as well as accelerated symmetric and asymmetric encryption
Darya [45]

Answer:

Hardware security module.

Explanation:

Hardware security module is a Physical digital device that comes as a plug-in adapter used to secure and manage digital keys and provides crypto processing for strong authentication.

It has an onboard cryptographic keyboard and one or more crypto processors, and can be used on computers and network servers to prevent logical or physical authentication access to unauthorized users. It supports symmetric and asymmetric cryptography.

8 0
3 years ago
Which of the following can ensily reverse motion and are better at varying speeds than electrical motors?
harkovskaia [24]

Answer:

Where are the following? You have to post the full question if you want help.

Explanation:

7 0
2 years ago
Other questions:
  • In Paint, which of the following are ways to use a picture that you have saved on your computer? (Select all that apply.)
    8·1 answer
  • To keep from overwriting existing fields with your Lookup you can use the ____________ clause.
    14·2 answers
  • On other questions, how do I write my own question, without commenting on others questions? It is only allowed two, I think, the
    13·1 answer
  • (Game Design) A float is a blank space, used as a placeholder in an array<br><br> True or false
    13·1 answer
  • Gary has to complete a form before enrolling into an online course. A few of the fields require Gary to respond with either a "Y
    7·2 answers
  • How to delete Brainly account ?​
    12·1 answer
  • When browsing using certain browsers, if a page is known to be malicious or using phishing techniques in the past a browser may
    5·1 answer
  • Convertbinary(111100)to decimal​​​​
    13·2 answers
  • In order to control access to a company's intranet and other internal networks, all communications pass through a _____ server.
    5·1 answer
  • Calculate the time complexity for the following function in terms of Big O notation. Explain your answer.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!