import java.util.Scanner;
class CurrencyExchange_1 {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.print("Input any 3 numbers");
int firstnumber = sc.nextInt();
int secondnumber = sc.nextInt();
int thirdnumber = sc.nextInt();
//Finding the bigger number
if (firstnumber > secondnumber);
if (firstnumber > thirdnumber ) {
System.out.println("Biggest number is " +firstnumber);
} else if (secondnumber > firstnumber);
if (secondnumber > thirdnumber); {
System.out.println("Biggest number is " +secondnumber);
} **else if** (thirdnumber > firstnumber);
if (thirdnumber > secondnumber); {
System.out.println("Biggest number is " +thirdnumber);
}
}
}
For the bolded part, I originally wrote only without the conditions but it was an error. Even with the code as written above, an error prompts for <'else' without 'if'>. I am not too sure where when wrong as if I completely deleted the last "else" part, the code works perfectly. I was reading answers for other questions that <else {...}> can work perfectly when not all conditions are met but it seems to be incorrect for me. Please pardon my complicated code because I am currently learning the basics and I am required to solve it using what I know currently which is just the comparing part of programming.
Aucun commentaire:
Enregistrer un commentaire