Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Just need program segments. JAVA Assume a Scanner object named input has already

ID: 3911663 • Letter: J

Question

Just need program segments. JAVA

Assume a Scanner object named input has already been defined. Write the statements (NOT an entire program) to:

Write the statements to define a method that accepts as parameters an array of Strings and the number of elements of the array and have the method display the contents of the array.

Ask the user for the number of classes a student wants to take in a given semester.

Define an array named course that can hold the name of courses for the number of courses entered by the user.

Write the statements to assign the value "CIT100" to all the elements of the array course.

Show how to call the method to display the content of the array course.

Explanation / Answer

1) statements to define a method that accepts as parameters an array of Strings and the number of elements of the array and have the method display the contents of the array.

public static void display(String arr[], int n){

System.out.println("Content of array is ");

for( int i=0;i<n;i++ ){

System.out.println(arr[i]);

}

}

2) Ask the user for the number of classes a student wants to take in a given semester.

int numClasses;

System.out.println("ENter the number of classes in the semester : ");

numClasses = sc.nextInt();

3) Define an array named course that can hold the name of courses for the number of courses entered by the user.

System.out.println("Enter the number of courses ");

int numCourses = sc.nextInt();

String course[] = new String[numCourses];

4) Write the statements to assign the value "CIT100" to all the elements of the array course

Arrays.fil(course, "CIT100");

5) Show how to call the method to display the content of the array course.

display(course, numCourses); // numCourses is the length of the array course