Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import static java.lang.System.*;
- import java.util.*;
- import java.io.*;
- public class Sort5Integers {
- public static void main(String[] args) {
- int myloop[] = new int[5];
- Scanner input = new Scanner(System.in );
- out.println("Enter 5 numbers.");
- for (int y = 0; y < myloop.length; y++) //Inputs numbers into myloop array.
- {
- myloop[y] = input.nextInt(); //Why do you think the loop does not care if the numbers are inputted separately or in one line?
- }
- out.println("Numbers entered into array.");
- int changed; //Why do you think having this is necessary?
- for (int sortloop = 0; sortloop < myloop.length; sortloop++) {
- for (int x = 0; x < myloop.length; x++) {
- if (myloop[sortloop] > myloop[x]) {
- changed = myloop[x];
- myloop[x] = myloop[sortloop];
- myloop[sortloop] = changed; //What do you think has happened here?
- }
- }
- }
- out.println("Sorting your numbers in descending order...");
- //This For Loop Prints sorted numbers.
- for (int sortloop = 0; sortloop < myloop.length; sortloop++) {
- out.println(myloop[sortloop]);
- }
- }
- for (int sortloop = 0; sortloop < myloop.length; sortloop++) {
- for (int x = 0; x < myloop.length; x++) {
- if (myloop[x] > myloop[sortloop]) {
- changed = myloop[sortloop];
- myloop[sortloop] = myloop[x];
- myloop[x] = changed;
- }
- }
- }
- for (int sortloop = 0; sortloop < myloop.length; sortloop++) {
- System.out.print(myloop[sortloop]);
- char asciiOfNumber = (char) myloop[sortloop];
- System.out.println(" " + asciiOfNumber);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement