Page 151 - CA_Blue( J )_Class10
P. 151

case "yellow":
                               System.out.println("Ready");
                               break;
                           case "green":
                               System.out.println("Go");
                               break;
                           default:
                               System.out.println("Invalid color");
                       }
                         What will be the output of the code?
                       a.  Stop                                        b.  Ready
                       c.  Go                                          d.  Invalid color

                    2.  Rohit is developing a user authentication system. The system should check if the entered username and password match the stored
                       username and password. The rules are as follows:
                        - If the username and password are correct, print "Access granted".
                        - If the username is correct but the password is incorrect, print "Incorrect password".
                        - If the username is incorrect, print "User not found".
                        Rohit writes the following code to implement these rules:
                       String storedUsername = "user123";
                       String storedPassword = "pass123";
                       String enteredUsername = "user123";
                       String enteredPassword = "pass124";
                       if (!enteredUsername.equals(storedUsername)) {
                           System.out.println("User not found");
                       } else if (!enteredPassword.equals(storedPassword)) {
                           System.out.println("Incorrect password");
                       } else {
                           System.out.println("Access granted");
                       }
                         What will be the output of the code?
                       a.  User not found                              b.  Incorrect password
                       c.  Access granted                              d.  Invalid credentials


                                             Previous Years' Questions



                                                              SECTION A

                    1.  The absence of which statement leads to fall through situation in switch case statement?      [2023]
                       a.  continue                                    b.  break
                       c.  return                                      d.  System.exit(0)
                   Ans.  b
                    2.  Choose the odd one:                                                                         [2022]
                       a.  if else                                     b.  if
                       c.  switch case                                 d.  while()
                   Ans.  d






                                                                                                                       149
                                                                                           Conditional Constructs in Java  149
   146   147   148   149   150   151   152   153   154   155   156