lundi 11 octobre 2021

how to call a method in if ternary operator in java? [duplicate]

if yn = "yes" i want call back the same method using if ternary operator.

 public static void addNewStudent(){
    Scanner input = new Scanner(System.in);
    String studentId = "";
    String studentName = "";
    System.out.print("Enter Student ID : ");
    studentId = input.nextLine();
    
    System.out.print("Enter Student Name : ");
    studentName = input.nextLine();
    
    System.out.println("Do you want to add new student : ");
    String yn = input.nextLine();
    
    //here is the if ternary operator
    yn = "yes" ? addNewStudent() : "completed"; //here i want to call the addNewStudent() again.
}

}

Aucun commentaire:

Enregistrer un commentaire