/** the String class introduces us to the data type used for text. */ /* def. of a string (in computer science) is a sequence of characters */ import java.util.Scanner; public class Strings { public static void main(String[] args) { String name1 = "John Doe"; /* you may also use new to create a String object, in a similar fashion to the creation of other objects. String nm = new String("John Doe"); // this would also work Scanner sc = new Scanner File infile = new File PrintWriter outfile = new PrintWriter int[] arr = new int... */ System.out.println("name1 is " + name1); String name2 = "Alice"; System.out.println("name2 is " + name2); if (name1.length() != name2.length()) System.out.println("length of name2 is: " + name2.length()); char firstInit = name2.charAt(0); System.out.println("name2's first initial is: " + firstInit); //name1 = "Alice"; Scanner sc = new Scanner(System.in); System.out.println("enter a name: "); name1 = sc.next(); // test if name1 equals to name2 if (name1 == name2) // NOT the way to do it System.out.println("name1 is equal to name2 " + name1); else System.out.println("name1 is: " + name1 + " name2 is: " + name2); if (name1.equals(name2)) ; } } /** Declare and read in 2 String objects. * Then, you are going to compare these 2 Strings without calling * .equals * hint: you can use for loop, you can loop up until the length of * a string. Really, you should first make sure that they have the * same length. you can call charAt to retreive each character that * needs to be compared. */