I need to compare the two inputs the user gives called age and answer2 in Java on repl.it I tried using greater than and less than signs, it still returns an error.
import java.util.*;
class Main {
public static void main(String[] args) {
Scanner vismay = new Scanner(System.in);
System.out.println("What is your name?");
String name = vismay.next();
System.out.println("What is your age?");
int age = vismay.nextInt();
System.out.println("Hi "+name);
System.out.println("You are "+age+" years old correct? Press t for true, f for false.");
String answer = vismay.next();
if(answer.equals("t")) {
System.out.println("What is your favorite number?");
int number = vismay.nextInt();
String answer2 = vismay.nextInt();
if(answer2.equals(age)){
System.out.println("You are going to be very famous");
}
else if(answer2.lessthan(age)){
System.out.println("You are going to be very rich");
}
else (answer2.greaterthan(age)){
System.out.println("You are very unlucky");
}
}
else {
System.out.println("What is your age?");
int age2 = vismay.nextInt();
System.out.println("You are "+age2+" years old correct? Press t for true, f for false.");
}
}
}
It returns:
Main.java:22: error: not a statement
else (answer2.greaterthan(age)){
^
Main.java:22: error: ';' expected
else (answer2.greaterthan(age)){
^
2 errors
compiler exit status 1
Aucun commentaire:
Enregistrer un commentaire