jeudi 29 juin 2017

can you have two conditions in an if statement

I'm a beginner in java coding, so I regularly browse to find beginner projects with my basic knowledge. I was recently working with to create a chatting programme where a user will chat with my computer. Here is a part of the code, since I don't need to show the whole code:

 System.out.println("Hello, what's our name? My name is " + answer4);
        String a = scanner1.nextLine();
        System.out.println("Ok, Hello, " + a + ", how was your day, good or bad?");
        String b = scanner2.nextLine();
        **if (b.equals("good"))** {
            System.out.println("Thank goodness");
        } else **if (b.equals("it was good"))** {
            System.out.println("Thank goodness");
        } else **if (b.equals("bad"))** {
            System.out.println("Why was it bad?");
            String c = scanner3.nextLine();
            System.out.println("Don't worry, everything will be ok, ok?");
            String d= scanner10.nextLine();
        }
        else **if (b.equals("it was bad"))**{
            System.out.println("Why was it bad?");
            String c = scanner3.nextLine();
            System.out.println("Don't worry, everything will be ok, ok?");
            String d= scanner10.nextLine();
        }

        if(age<18){System.out.println("How was school?");}
        else if (age>=18){System.out.println("How was work?");}

The conditions of the if statements are in Bold. The first and the second are similar, and so are the third and fourth. I thought it was possible to make them this, but it wasn't:

 if (b.equals("good"),b.equals("it was good")) {
            System.out.println("Thank goodness");
        }  else if (b.equals("bad"),(b.equals("it was bad"))) {
            System.out.println("Why was it bad?");
            String c = scanner3.nextLine();
            System.out.println("Don't worry, everything will be ok, ok?");
            String d= scanner10.nextLine();
        }

Can someone correct it for me pls? I'd really appreciate it!

Aucun commentaire:

Enregistrer un commentaire