Java: Do While with || and && operators -


so i'm bit confused on following:

while testing boolean, first impression use || operator conditions. did not work, loop keep repeating correct response. if used && operator, evaluate conditions way wanted to.

i feel backwards, , i'm not looking @ right. can explain this?

to make more clear, trying do:

    string input; scanner keyboard = new scanner(system.in);  {     system.out.print("enter 1 of following names: john, katie, richard");     input = keyboard.nextline();     input = input.tolowercase();  } while ( !input.equalsignorecase("john") && !input.equalsignorecase("katie") && !input.equalsignorecase("richard")); 

i want loop repeat until 1 of given names entered. if entered katie, should move on, if enter bob should repeat.

so if enter john, boolean first checks that. !(john = john) ft = false. since want check see if equal john, not richard or katie want use || operator. why want check if equal names anyway.

this basic boolean logic. statement equivalent !a && !b && !c - in turn equivalent !(a || b || c)

the simplest way reason these via logic tables:

a b c | !a !b !c | !a && !b && !c | || b || c | !(a || b || c) ------+----------+----------------+-------------+--------------- f f f |  t  t  t |        t       |      f      |        t       t f f |  f  t  t |        f       |      t      |        f       f t f |  t  f  t |        f       |      t      |        f       t t f |  f  f  t |        f       |      t      |        f       f f t |  t  t  f |        f       |      t      |        f       t f t |  f  t  f |        f       |      t      |        f       f t t |  t  f  f |        f       |      t      |        f       t t t |  f  f  f |        f       |      t      |        f       

as can see 2 expressions have same boolean values in cases.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -