vendredi 15 mai 2020

about java string comparison [duplicate]

I need if enter letter Y or y, continue the programe.But logic is incorrect.

    import java.util.*;
class Demo{
    public static void main(String args[]){
        Scanner input=new Scanner(System.in);
        String [][]Student=new String[100][2];  

        String yno="Y",yno2="y",yn="y";
        //~ System.out .println(yn==yno2);
            for (int i = 0; i < Student.length; i++){
                System.out .print("Student has been added successfully. Do you want to add a new student (Y/n) : ");
                    yn=input.nextLine();
                    System.out .println(yn);

                if(yn==yno2 || yn==yno){
                    System.out.print("Enter Student ID : ");
                    Student[i][1]=input.nextLine();

                    System.out.print("Enter Student Name : ");  
                    Student[i][1]=input.nextLine();



                }else{
                    break;
                }
            }System.out .println(yn==yno2);



    }

}

if you enter y or Y.then continue for loop.but if(yn==yno2 || yn==yno); statement is false? how can I get true

Aucun commentaire:

Enregistrer un commentaire