Computer Science, asked by juliajackobs123, 1 year ago

Write a menu driven program in java to take input a number and to arrange the digits of the number in ascending or descending order as per user's choice. Make suitable use of methods.

Answers

Answered by myselfThakur
4

Explanation:

import java.util.Scanner;

public class Experiment

{

public static void main(String args[])

{

Scanner scan = new Scanner(System.in);

int tenNums[]=new int[10], orderedNums[]=new int[10];

int greater;

String choice;

//get input

System.out.println("Enter 10 integers : ");

for (int i=0;i ");

tenNums[i] = scan.nextInt();

}

System.out.println();

//imperfect number ordering algorithm

for(int indexL=0;indexLtenNums[indexR])

{

greater++;

}

}

orderedNums[greater]=tenNums[indexL];

}

//ask if ascending or descending

System.out.print("Display order :\nA - Ascending\nD - Descending\nEnter your choice : ");

choice = scan.next();

//output the numbers based on choice

if(choice.equalsIgnoreCase("a"))

{

for(greater=0;greater-1;greater--)

{

System.out.print(orderedNums[greater]+" ");

}

}

}

}

Similar questions