Answer to Question #145316 in Java | JSP | JSF for Hamza saeed

Question #145316
Write a program that prompts the user to input three numbers. The
program should then output the numbers in nondescending order.
1
Expert's answer
2020-11-23T14:36:53-0500
import java.util.Scanner;
class Main
{
  public static void main (String[]args)
  {
    Scanner in = new Scanner (System.in);
    int[] numbers = new int[3];
    for (int i = 0; i < numbers.length; i++)
      {
    System.out.println ("Enter a number:");
    numbers[i] = in.nextInt ();
      }
    for (int i = 0; i < numbers.length; i++)
      {
    for (int j = i; j < numbers.length; j++)
      {
        if (numbers[i] > numbers[j])
          {
        int tmp = numbers[i];
        numbers[i] = numbers[j];
        numbers[j] = tmp;
          }
      }}
    for (int i = 0; i < numbers.length; i++)
      {
    System.out.print (numbers[i] + " ");
      }
    System.out.println ();
  }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS