Question

WRITE THIS PROGRAM IN JAVA CODING ONLY ! Program 1: In Order Using an IF/ELSE IF/ELSE...

WRITE THIS PROGRAM IN JAVA CODING ONLY !

Program 1: In Order

Using an IF/ELSE IF/ELSE structure, write a program that will prompt the user for three numbers and displays them in ascending order.

  • First, the program will prompt the user for each of the three numbers.
  • Next, find the smallest value of the three.
  • Then decide which of the other two is the next smallest.
  • Then have the program display the three numbers in ascending order.

Be sure to do the following:

  1. Determine what the input will be, it's data type, and assign a variable for each value.
  2. Determine what the output will be. Do you need new variables for the output or can you use the input again? There is no right or wrong answer here. It’s also possible you may have to develop your algorithms before you can decide whether you will use new variables for your output or just use the input variables. You can always change your mind if you find you need to.
  3. Do you need any formulas?
  4. Create an initial algorithm of the basic steps.
  5. Develop the refined algorithm from the initial algorithm.

Be sure to include with your program as documentation:

  1. The Program Prologue
  2. The Input data
  3. The Output data
  4. Any Formulas you may have.
  5. The Initial Algorithm
  6. The Refined Algorithm

NOTE 1:

  • DO NOT use the "return 0" code, end, break, or exit to force an exit from within your IF/ELSE structure.  Declare all variables within the data declaration section.
    • Let the program progress to the end of the main function.
    • The end of the main function is the only place that the “return 0” should be placed.
    • A SWITCH statement is the only place that the break command should be used.
  • DO NOT use the "continue" statement.

NOTE 2:
1. Declare all variables within the data declaration section of each class and method.  (-5)
2   Do not get input on the same line as a variable declaration.  
(-5)

3. Do not place an equation for computation on the same line as declaring a variable.  (-5)

Test your program with the following sets of data:

  1. First number: 3
    Second number: 2
    Third number: 1
  2. First number: 3
    Second number: 1
    Third number: 2
  3. First number: 1
    Second number: 2
    Third number: 3
  4. First number: 1
    Second number: 3
    Third number: 2
  5. First number: 2
    Second number: 1
    Third number: 3
  6. First number: 2
    Second number: 3
    Third number: 1
0 0
Add a comment Improve this question Transcribed image text
Answer #1


/*
first find smaller between n1 and n2 and store in n1;

then find smaller between n1 and n3 store it in n1;
now find smaller between n2 and n3 and store it in n2

*/

import java.util.Scanner;

class Main
{
  
static Scanner sc = new Scanner(System.in);
public static void main(String args[])
{
  
int n1, n2, n3; // decalre three variables
int temp;
  
  
System.out.println("Enter Three number");
  
n1= sc.nextInt();
n2= sc.nextInt(); // read three numbers
n3= sc.nextInt();
  
  
System.out.println(" The number you entered are "+ n1 +" "+ n2 + " "+ n3);
  
if(n1>n2)
{
temp=n1;
n1=n2;
n2=temp;
  
  
}
  
if(n1>n3)
{
temp=n1;
n1=n3;
n3=temp;
  
  
}
  
if(n2>n3)
{
temp=n2;
n2=n3;
n3=temp;
  
  
}
  
System.out.println(" The numbers are "+ n1 +" "+ n2 + " "+ n3);
  
  
}
  
  
  
  
}

Add a comment
Know the answer?
Add Answer to:
WRITE THIS PROGRAM IN JAVA CODING ONLY ! Program 1: In Order Using an IF/ELSE IF/ELSE...
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
  • In C++ Write a program that will calculate the cost of a phone call as follows:...

    In C++ Write a program that will calculate the cost of a phone call as follows: The first 10 minutes are charged at a flat rate of $0.99 for the entire 10 minutes (Not 99 cents a minute - but 99 cents for the first 10 minutes total). Every minute after the initial 10 minutes will be charged at $0.10 per minute. Input the number of minutes talked as an integer. Using an IF/ELSE structure, check for an entry of...

  • Topics If/Else statement Description    Write a program that determines the larger of the two numbers...

    Topics If/Else statement Description    Write a program that determines the larger of the two numbers provided by the user. The program asks the user to enter a number. Then it asks the user to enter another but a different number. Then, it determines the larger of the two numbers and displays it to the user. (If the user happens to enter the two numbers the same, the program may report either of the two numbers as larger.) Requirements Do...

  • Create a program in Java with the following requirements: Using a Scanner and print statements, ask...

    Create a program in Java with the following requirements: Using a Scanner and print statements, ask the user to input 3 numbers. Use Java’s int data type…don’t worry about error checking for this assignment (assume the user doesn’t try to break your program) Store these three numbers into three variables Calculate the sum of all three numbers Calculate the product of all three numbers If all three numbers are even, output “Lucky Duck!” If all three numbers are odd, output...

  • Write a Java program that uses six grades as integer values and calculate their average. Result...

    Write a Java program that uses six grades as integer values and calculate their average. Result must be printed as a floating data type. Design your program using the following specifications. 1. You must declare integer variables to hold the grades. Assume grades are always integer. 2. Result must be stored in a separate variable. 3. All numbers in the output must be in floating data type. 4. All grades must be displayed in one significant digit floating number. 5....

  • c++ class, coding using code blocker MinilabLoopLogic The program: You are to write a program called...

    c++ class, coding using code blocker MinilabLoopLogic The program: You are to write a program called MinilabLoopLogic which does the following Asks the user to enter 2 integers (can be one prompt or two) Gets and stores the ints Explains that the program will generate all integers that are between the numbers and are divisible by a third integer . e Asks the user for the number they should be divisible by Gets and stores that int Since 0 will...

  • 1- Correct the syntax errors in the following program, and rewrite the program so that it...

    1- Correct the syntax errors in the following program, and rewrite the program so that it follows the proper style conventions. What does the program do? (Write it out as a comment). (10 pts) #include <stdio.h> int main() {/* * Calculate and display the difference of two values *) int X, /* first input value */ x, /* second input value */ sum; /* sum of inputs */ X=9, x=7.5 X + x = sum; printf("%d + %d = %d\n";...

  • Swapping Values in python Summary In this lab, you complete a Python program that swaps values...

    Swapping Values in python Summary In this lab, you complete a Python program that swaps values stored in three variables and determines maximum and minimum values. The Python file provided for this lab contains the necessary input and output statements. You want to end up with the smallest value stored in the variable named first and the largest value stored in the variable named third. You need to write the statements that compare the values and swap them if appropriate....

  • C++ programming please Write a program that will display random numbers in order from low to...

    C++ programming please Write a program that will display random numbers in order from low to high. 1. Declare an integer array of size 100. Ask the user how many numbers to work with (n). It can be less than 100. 2. Generate random numbers from 10 to 50. 3. Write the random numbers to an output file named random.dat. Close the file. 4. Open random.dat for input and read the data values into your array. Pass your array to...

  • In Java Code Needed is Below the Question Using Program 3: Encapsulating Dogs, modify this program...

    In Java Code Needed is Below the Question Using Program 3: Encapsulating Dogs, modify this program to create a database of dogs of your own. You will also include File I/O with this program. You will create 3 classes for this assignment. The first class: Create a Class representing the information that is associated with one item (one dog) of your database. Name this class Dog. Using Lab 3, this will include the information in regard to one dog. The...

  • Use only if else nested if else only otherwise your answer won't be entertained. Problem 1(b):...

    Use only if else nested if else only otherwise your answer won't be entertained. Problem 1(b): Write a program that gives remainder without using modulus operator and loops. The first number entered will be dividend and second number entered will be divisor. Sample input: 15 6 Sample output: Remainder is 3 In a right triangle, the square of the length of one side is equal to the sum of the squares of the length of the other two sides. Write...

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