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

T. In this activity, you will have to do the following Printing Names 1/ Ask the

ID: 3667524 • Letter: T

Question



T. In this activity, you will have to do the following Printing Names 1/ Ask the user to enter a se variables called name1, name2, .., name10, each variable of type String ries of 10 names. You should store each of these names in ou will then proceed by outputting on System.out the list of these names (starting with name1 until name10), each separated by a comma followed by a space 3/ You will then swap the content of name1 with the content of name10, the content of name 2 with the content of name. · . the content of name3 with the content of names e the content of name4 with the content of name?, and the content of names with the content of name. 4/ You will then proceed by outputting on System.out the list of the names (starting with name1 until name10), each separated by a comma followed by a space (Note: It should in fact be the same line of code as the one written to fuliN Step 2.) Special requirement of the code you have to write: In order to fulfill the above requirements, you will have to define variables of type String. Very expectedly, you will need ten of them to hold the 10 names. In case you are planning to define more variables, you are not allowed to use more than one more vartable of type String So in total in your code, you are only allowed to use 11 String variables The java file lab3Spring16Act1.java, which contains the code for the above steps, where instructed in the file. 1.

Explanation / Answer

package movie_Rating;

import java.util.Scanner;

public class StringSwapping {


   
    public static void main(String[] args) {
String name1,name2,name3,name4,name5,name6,name7,name8,name9,name10;
String name11;
Scanner str=new Scanner(System.in);
name1=str.next();
name2=str.next();
name3=str.next();
name4=str.next();
name5=str.next();
name6=str.next();
name7=str.next();
name8=str.next();
name9=str.next();
name10=str.next();
       
System.out.println("name1 "+name1);
System.out.println("name2 "+name2);
System.out.println("name3 "+name3);
System.out.println("name4 "+name4);
System.out.println("name5 "+name5);
System.out.println("name6 "+name6);
System.out.println("name7 "+name7);
System.out.println("name8 "+name8);
System.out.println("name9 "+name9);
System.out.println("name10 "+name10);

name11=name10;
name10=name1;
name1=name11;


name11=name9;
name9=name2;
name2=name11;

name11=name8;
name8=name3;
name3=name11;

name11=name7;
name7=name4;
name4=name11;

name11=name6;
name6=name5;
name5=name11;

System.out.println("name1 "+name1);
System.out.println("name2 "+name2);
System.out.println("name3 "+name3);
System.out.println("name4 "+name4);
System.out.println("name5 "+name5);
System.out.println("name6 "+name6);
System.out.println("name7 "+name7);
System.out.println("name8 "+name8);
System.out.println("name9 "+name9);
System.out.println("name10 "+name10);


    }

}