+ 2

Java

what is my mistake ? I don’t get the output import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner input=new Scanner(System.in); int v=input.nextInt(); System.out.println("Entered value is:"+v); if(v==1) { System.out.println("Hi"); } elseif(v==2); { System.out.println("Hello"); } else { System.out.println("No match found"); } } }

18th Nov 2018, 8:20 AM
Jothika
Jothika - avatar
3 Respostas
+ 9
Try this: import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner input=new Scanner(System.in); int v=input.nextInt(); System.out.println("Entered value is:"+v); if(v==1){ System.out.println("Hi"); } else if(v==2) { System.out.println("Hello"); } else { System.out.println("No match found"); } } } It is else if() not elseif and you should delete the ; after the else if.
18th Nov 2018, 8:49 AM
Uni
Uni - avatar
+ 4
it should be else if not elseif
18th Nov 2018, 8:45 AM
Lambda_Driver
Lambda_Driver - avatar
0
import java.util.Scanner; public class tc { public static void main(String...Naufal) { Scanner input = new Scanner(System.in); int v = input.nextInt(); System.out.println("Entered value is:" + v); if (v == 1){ System.out.println("Hi"); }else if(v == 2){ System.out.println("Hello"); }else{ System.out.println("No match found"); } } } // you should remove the semicolon ";" at the end of else if() declaration /* 2 Entered value is:2 Hello */
18th Nov 2018, 12:13 PM
Nopal Opal
Nopal Opal - avatar