+ 3

what is the 4th hidden test case in the BOT practice question in introduction to java ,in the 4th module

import java.util.Scanner; public class Program { //your code goes here static void bot(){ Scanner sc = new Scanner(System.in); int message = sc.nextInt(); if (message == 1){ System.out.println("Order Confirmed"); } else if (message == 2){ System.out.println("info@sololearn.com"); } else if( message != 1 | message != 2){ System.out.println("Try again"); } else{ System.out.println("Retry"); } } /* User message: "1", Reply: "Order confirmed" User message: "2", Reply: "info@sololearn.com" For any other number, the reply should be: "Try again". */ public static void main(String[] args) { Program b=new Program(); bot(); } } This is the code : please help if there is some error

2nd Sep 2023, 9:34 AM
Andrew Coutinho
Andrew Coutinho - avatar
1 Respuesta
+ 1
Hi, the 4th 'else' will never be true since the 3rd is checking if message 1 or 2 not is entered, you do not even need this line of code else if( message != 1 || message != 2){ System.out.println("Try again"); } You can replace it with the 'else' like this if (message == 1){ System.out.println("Order Confirmed"); } else if (message == 2){ System.out.println("info@sololearn.com"); } else{ System.out.println("Try again"); }
2nd Sep 2023, 12:33 PM
JavaBobbo
JavaBobbo - avatar