Question: Using the Course Resource from Week Two called Understanding Pseudocode, Flowcharts, and the Test Plan, create a Word document that contains the pseudocode, flowchart, and

Using the Course Resource from Week Two called Understanding Pseudocode, Flowcharts, and the Test Plan, create a Word document that contains the pseudocode, flowchart, and test plan
Project 5
Write the following method that returns true if the list is already sorted in increasing order.
public static boolean isSorted(int[] list)
Write a test program that prompts the user to enter a list and displays whether the list is sorted or not.
Here is a sample run.
Sample Run 1
Enter the size of the list: 8
Enter the contents of the list: 101516619111
The list has 8 integers 101516619111
The list is not sorted
Sample Run 2
Enter the size of the list: 10
Enter the contents of the list: 113445791121
The list has 10 integers 113445791121
The list is already sorted
Class Name: Exercise07_19
Code:
import java.util.Scanner;
public class Exercise07_19{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.print("Enter the size of the list: ");
int size = input.nextInt();
int[] list = new int[size];
System.out.print("Enter the contents of the list: ");
for (int i =0; i < size; i++){
list[i]= input.nextInt();
}
System.out.print("The list has "+ size +" integers ");
printArray(list);
if (isSorted(list)){
System.out.println("The list is already sorted");
} else {
System.out.println("The list is not sorted");
}
input.close();
}
public static boolean isSorted(int[] list){
for (int i =0; i < list.length -1; i++){
if (list[i]> list[i +1]){
return false;
}
}
return true;
}
public static void printArray(int[] arr){
for (int num : arr){
System.out.print(num +"");
}
System.out.println();
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!