import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int[] arr = new int[7]; boolean isSorted = true; int buf; for (int i = 0; i < arr.length; i++) { System.out.print("Month " + (i + 1) + ": "); arr[i] = in.nextInt(); } for (int i = 0; i < arr.length; i++){ for (int j = 0; j < arr.length - 1; j++) { if (arr[i] < arr[j]) { buf = arr[i]; arr[i] = arr[j]; arr[j] = buf; } } } for (int i : arr) { System.out.print(i + " "); } } }
This is the code i want pseudocode and flowchart of this code.
/*
In the main function
Declare an array of 7 elements
Repeat steps 0 to 7{
Get number from user
}
Repeat steps 0 to 7{
Repeat steps 0 to 7{
Compare all numbers with each other
If the first number is less than the second,
we swap them so that the smaller number goes forward and the larger one goes back.
If the first number is greater than the second,
skip and compare the first with the third, and so on.
When we compare the first number with all, we move on to the second and so on.
}
}
Repeat steps 0 to 7{
Output all sorted numbers from the array
}
*/
Comments
Leave a comment