This code is to compare 2 strings entered by the user and it's supposed to output whether the first string is > < or = the second string.
It's working for the most part except when I enter two phrases like gh and hi, it thinks gh is greater than hi. Maybe it's looking at the size of the actual letter.
package com.mycompany._3;
import java.util.Scanner;
public class App {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
System.out.print("Enter first phrase(s): ");
String one = scanner.next();
System.out.print("Enter Second phrase(s): ");
String two = scanner.next();
int length = one.compareTo(two);
if(length > 0){
System.out.print("String one is less than string two.");
}else if (length < 0)
System.out.print("String one is greater than string two.");
else
System.out.print("Both phrases are equal length");
}
}