Question

In: Computer Science

Suppose you have three, user input temperatures (double) assigned to three objects (chem1, chem2, and chem3)....

Suppose you have three, user input temperatures (double) assigned to three objects (chem1, chem2, and chem3). How would you go about finding which of the three values entered by the user is closest to the value 240.00 WITHOUT THE USE OF LOOPS OR ARRAYS? Solve using Java Programming Language.

Solutions

Expert Solution

Explanation:

Here is the code which takes the values chem1, chem2 and chem3 from the user input and then after calculating the mod of difference of each one from 240, it decides which of the number is the closest to 240.0

Code:

import java.util.Scanner;

public class Main
{
   public static void main(String[] args) {
  
double chem1, chem2, chem3;      
  
Scanner sc = new Scanner(System.in);
  
chem1 = sc.nextDouble();
chem2 = sc.nextDouble();
chem3 = sc.nextDouble();
  
double diff1, diff2, diff3;
  
diff1 = chem1 - 240;
diff2 = chem2 - 240;
diff3 = chem3 - 240;
  
if(diff1<0)
diff1 = -diff1;
  
if(diff2<0)
diff2 = -diff2;
  
if(diff3<0)
diff3 = -diff3;
  
if(diff1<=diff2 && diff1<=diff3)
{
System.out.println(chem1+" is the closest to 240.0");
}
else if(diff2<=diff1 && diff2<=diff3)
{
System.out.println(chem2+" is the closest to 240.0");
}
else
{
System.out.println(chem3+" is the closest to 240.0");
}
      
   }
}

Output:

PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!

PLEASE COMMENT IF YOU NEED ANY HELP!


Related Solutions

Write an interactive C++·program to have a user input their three initials and the length of...
Write an interactive C++·program to have a user input their three initials and the length of three sides of a triangle. Allow the user to enter the sides in any order. Determine if the entered sides form a valid triangle.The triangle may not have negative sides.The sum of any two sides must be greater than the third side to form a triangle. Determine if the entered sides are part of a scalene, isosceles, or equilateral triangle. Using the Pythagorean Theorem,...
Read three integers from user input.
Read three integers from user input.
You have been asked to write program that allows the user to input a first name,...
You have been asked to write program that allows the user to input a first name, middle initial (without the period), and last name of a user and then display that person’s name with the first, middle initial followed by a period, and last name last. BEFORE creating the program, use structured programming principles to document how you are going to develop the program. Use Microsoft Word to complete this part of the assessment. Answer each of the following areas:...
Assume that you have three objects. Think and describe whether it is possible to create a...
Assume that you have three objects. Think and describe whether it is possible to create a state where all three objects are going to be at rest taking gravitational interaction among them into account. Assume that we have three objects with electric charges, two with a positive and one with a negative electric charge and think and describe whether it is possible to realize such a state where all three are static. Assume that it is not just a single...
Three solid objects (A, B, and C) are placed in water. The objects each have constant...
Three solid objects (A, B, and C) are placed in water. The objects each have constant densities of 160, 260, and 745 kg/m3, respectively. a.) How do you immediately know all three objects will float? b.) Find the fraction of the volume submerged for each object. A: B: C: c.) If object C has the dimensions (length=8 m, width=7 m, height=3 m), how far does this object stick out of the water when floating (in this orientation)? m
In c++, Can anyone make these code int user input as user have to put all...
In c++, Can anyone make these code int user input as user have to put all the amount. int main()    {        Polygon p1(3,4,4.5,5.5);        Polygon p2(4,4,5.5,6.5);        Polygon p3(5,4,6.5,7.5);               cout<<"Area of Polygon#1:"<<p1.getArea()<<endl;        cout<<"Perimeter of Polygon#1:"<<p1.getPerimeter()<<endl;               cout<<"\nArea of Polygon#2:"<<p2.getArea()<<endl;        cout<<"Perimeter of Polygon#2:"<<p2.getPerimeter()<<endl;               cout<<"\nArea of Polygon#3:"<<p3.getArea()<<endl;        cout<<"Perimeter of Polygon#3:"<<p3.getPerimeter()<<endl;                         return 0;     ...
Suppose you are a stock analyst and have been assigned to follow a company that went...
Suppose you are a stock analyst and have been assigned to follow a company that went public two years ago. In the three years prior to going public, the firm saw on average 20% quarterly growth in sales. Since going public, you have noticed a decline in the growth rate of sales, and in the last quarter the firm announced a 12% increase in sales. You have been given the task of forecasting the next two years of sales for...
You proceed to measure the equilibrium constant at three more temperatures, and now have the following...
You proceed to measure the equilibrium constant at three more temperatures, and now have the following results: Temperature (K) Equilibrium constant 100.0 ± 0.01 (1.6±0.1) ×104 150.0±0.01 (3.3±0.1) ×104 200.0 ± 0.01 (5.7±0.1) ×104 250.0±0.01 (6.2±0.1) ×104 300.0±0.01 (7.8±0.1) ×104 (a) Linearize your date and perform a linear regression, using Excel or another computer program. Use the program to find the slope, intercept, and uncertainties in the slope and intercept. (b) Make a figure of the linearized data in 7(a);...
MIPS ASSEMBLY Have the user input a string and then be able to make changes to...
MIPS ASSEMBLY Have the user input a string and then be able to make changes to the characters that are in the string until they are ready to stop. We will need to read in several pieces of data from the user, including a string and multiple characters. You can set a maximum size for the user string, however, the specific size of the string can change and you can’t ask them how long the string is (see the sample...
Write an application and perform the following:(NO USER INPUT) -Create at least three classes such as:...
Write an application and perform the following:(NO USER INPUT) -Create at least three classes such as: 1. listnode- for data and link, constructors 2. Singlelinkedlist-for method definition 3. linkedlist-for objects -Insert a node at tail/end in a linked list. -and display all the nodes in the list. -Delete a node at a position in the list Note: Add these methods in the same application which we have done in the class. this is what we've done in the class: class...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT