Assignment/Lab Documentation At the beginning of each programming assignment you
ID: 3598646 • Letter: A
Question
Assignment/Lab Documentation At the beginning of each programming assignment you must have a comment block with the following information: AUTHOR: your name /FILENAME: title of the source file / SPECIFICATION: description of the program // FOR: CSE 110-Lab #3 /TIME SPENT: how long it took you to complete the assignment Getting Started Create a class called Lab3. Use the same setup for setting up your class and main method as you did for the previous assignments. Be sure to name your file Lab3.java. Part 1: String Comparison In your main method, write a segment of code which will read in two strings and output whether the strings are equal or not. For example, if both Strings have the value "hello", the following should be printed:Explanation / Answer
import java.util.Scanner;
public class slength {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
System.out.print("Enter string 1:");
String s1=in.nextLine();
System.out.print("Enter string 2:");
String s2=in.nextLine();
if (s1.length()>s2.length())
System.out.println("""+s1+"" is larger than ""+s2+""");
else if (s1.length()<s2.length())
System.out.println("""+s2+"" is larger than ""+s1+""");
else
System.out.println("The strings have the same length.");
in.close();
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.