Read in a line of text Use String class methods to manipulat
Solution
Please find my implementation.
Please let me know in case of any issue.
import java.util.Scanner;
public class Lab6a {
public static void main(String[] args) {
// creating an Scanner Object
Scanner sc = new Scanner(System.in);
//1 getting line1 test
System.out.println(\"Enter line1 text: \");
String line1 = sc.nextLine();
// 2. print line1
System.out.println(line1);
// 3 print each character of line1 on separate line
for(int i=0; i<line1.length(); i++)
System.out.println(line1.charAt(i));
// 4 print from second character and print first character at last
for(int i=1; i<line1.length(); i++)
System.out.print(line1.charAt(i));
System.out.println(line1.charAt(0)); // printing first character at last
// 5 print all character of line1 in uppercase
System.out.println(line1.toUpperCase());
// 6 getting another line
System.out.println(\"Enter line2: \");
String line2 = sc.nextLine();
if(line1.compareTo(line2) > 0){// line1 > line2
System.out.println(line2);
System.out.println(line1);
}
else{ // line1 <= line2
System.out.println(line1);
System.out.println(line2);
}
}
}
/*
Sample run:
Enter line1 text:
THis is Text
THis is Text
T
H
i
s
i
s
T
e
x
t
His is TextT
THIS IS TEXT
Enter line2:
his is texg
THis is Text
his is texg
*/
