In this exercise you will debug the code which has been provided in the starter file. The code is intended to do the following:

take a string input and store this in the variable str1
copy this string into another variable str2 using the String constructor
change str1 to the upper-case version of its current contents
print str1 on one line, then str2 on the next

1 /* Lesson 4 Coding Activity Question 2 */
2
3 import java.util.Scanner;
4
5 public class U2_L4_Activity_Two{
6 public static void main(String[] args){
7
8 Scanner = new Scanner(System.in);
9 String str1 = scan.nextLine();
10 String str2 = String(str1);
11 str1 = toUpperCase(str1);
12 System.out.println("str1");
13 System.out.println("str1");
14
15 }
16 }

Respuesta :

Answer:

The corrected code is as follows:

import java.util.Scanner;

public class U2_L4_Activity_Two{

public static void main(String[] args){

Scanner scan = new Scanner(System.in);

String str1 = scan.nextLine();

String str2 = str1;

str1 = str1.toUpperCase();

System.out.println(str1);

System.out.println(str2);

}

}

Explanation:

This corrects the scanner object

Scanner scan = new Scanner(System.in);

This line is correct

String str1 = scan.nextLine();

This copies str1 to str2

String str2 = str1;

This converts str1 to upper case

str1 = str1.toUpperCase();

This prints str1

System.out.println(str1);

This prints str2

System.out.println(str2);