I created two Scanner objects ant got them. but when getting inputs is finished, if/else codes do not work. where is the problem? can you explain me please and write the right code?tnx.
import java.util.Scanner;
public class NestedIf {
public static void main(String[] args) {
Scanner iqInput=new Scanner(System.in);
System.out.println("Please enter your IQ: ");
iqInput.nextDouble();
Scanner termMeanInput=new Scanner(System.in);
System.out.println("Please enter your term mean: ");
termMeanInput.nextDouble();
if(iqInput.hasNextDouble() && termMeanInput.hasNextDouble()){
if(iqInput.nextDouble()>110 && termMeanInput.nextDouble()>18){
System.out.println("You got 30 percent discount.");
}else if(iqInput.nextDouble()>100 && termMeanInput.nextDouble()>17){
System.out.println("You got 20 percent discount.");
}else if(iqInput.nextDouble()<100 && termMeanInput.nextDouble()<17){
System.out.println("You have no discount");
}
}else{
System.out.println("Please enter the right format");
}
}
}
Aucun commentaire:
Enregistrer un commentaire