lundi 10 octobre 2016

If an else statement in java programming

Below are the totally of my java program; what i need is that i have three queries, if three of them replied to Y for yes, then the program should execute the first if, and if two of them then the program should compile the second one and one of them should run with the fourth one. otherwise compile the last one.

but the program always runs with last one!!!.

"""Does any one can understand and help me???""

import java.util.Scanner; public class GradesofStudents {

public static void main(String[] args) {
    // TODO Auto-generated method stub

    Scanner examing = new Scanner(System.in);


    System.out.println("Please answer few questions to examine your understanding of JAVA programmiing language");
    System.out.println("Did you solve the first home work?");
    String firstQ = examing.nextLine();
    System.out.println("Did you solve the second home work?");
    String secondQ = examing.nextLine();
    System.out.println("Do you participate the activities in the class?");
    String thirdQ = examing.nextLine();

    if (firstQ == "y" && secondQ == "y" && thirdQ == "y")
    {
        System.out.println("Congratulation!, You're excellent");
    }
    else  if (firstQ == "y" && secondQ == "y" || thirdQ == "y")
    {
        System.out.println("Very Good");    
    }
    else if(firstQ == "y" || secondQ == "y")
    {
        System.out.println("You're about to die");
    }
    else

    {
        System.out.println("You're under ground!");
    }

}

}

Aucun commentaire:

Enregistrer un commentaire