Computer Science, asked by Thebrain0078462, 11 months ago

write a java program to assign a number and print it in ascending order without input statement.

Answers

Answered by Nikhil0204
1

ANSWER :-

Anyway this is the code that I came up with.

import java.util.Scanner;

public class Ch5PA1

{

public static void main(String[] args) {

// Declarations

Scanner input = new Scanner(System.in);

System.out.print("Enter three values: ");

int num1 = input.nextInt();

int num2 = input.nextInt();

int num3 = input.nextInt();

}

/** Sort Numbers */

public static void displaySortedNumbers(double num1, double num2, double num3){

if ((num1 < num2) && (num2 < num3)){

System.out.println("The sorted numbers are " + num1 + " " + num2 + " " + num3);

}

if ((num1 < num2) && (num2 > num3)){

System.out.println("The sorted numbers are " + num1 + " " + num3 + " " + num2);

}

if ((num1 > num2) && (num2 > num3)){

System.out.println("The sorted numbers are " + num3 + " " + num2 + " " + num1);

}

if ((num1 > num2) && (num2 < num3)){

System.out.println("The sorted numbers are " + num2 + " " + num1 + " " + num3);

}

}

}

Another thing, looking around I saw a few questions people asked about the same (or similar) issues I am having with this but the replies insist on using arrays. I cannot use an array at all for this.

HOPE THIS HELPS YOU!!!!!!!!!!!

PLEASE MARK IT AS BRAINLIST!!!!!!!!!!!

Similar questions