+ 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"); } } }
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.
+ 4
it should be else if not elseif
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
*/