I have a kind of complex problem that I hope I can get some help on. My teacher has asked for a homework question that we find how long it took us to type a sentence "Hello World!" and print it out in milliseconds using the Date class while also checking if it is correct. This is what I have so far
import java.util.*;
public class Date
{
public static void main(String[] args)
{
Scanner hello = new Scanner (System.in);
Date d1 = new Date();
System.out.println("Your job is to type the sentence \"Hello World!\" as fast as you can.");
System.out.println("When you are ready, press enter, type the sentence, and press enter again.");
System.out.println("");
String sen = hello.nextLine();
if(sen == "Hello World!")
{
System.out.println(d1.getTime());
}
if (sen != "Hello World!")
{
System.out.println("Incorrect Input");
}
}
}
I looked some stuff up and I'm trying to use the getTime method, but it just doesn't let me use it.
My main idea is to use getTime to check how long it took the user to input the sentence, but I am just not at all sure how to do that.