+ 1
Can you please show me what are the mistakes in this code? (In the description)
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner name = new Scanner(System.in); Scanner age = new Scanner(System.in); if(age< 16){ System.out.println (name.nextLine()); }else{ Scanner add = new Scanner(System.in); System.out.println (age.nextInt()); } } }
5 Respostas
+ 3
You're not taking any input and storing it.
Try this one
class Test
{
public static void main (String[] args) throws Exception
{
Scanner name = new Scanner(System.in);
Scanner age = new Scanner(System.in);
String NAME=name.nextLine();
int AGE=age.nextInt();
if(AGE<=16){
System.out.println("Name:"+NAME);
}else{
System.out.println("Age:"+AGE);
}
name.close();
age.close();
}
}
+ 1
Without taking the value in age..
how you compare first..
at the time you declared age..
age only hold the reference id of object of scanner class..
you first provide a value..
before compair
+ 1
You Didn't Entered The Value Of Age.You Should Do that and Run The Code It will Work.
0
bro I'm taking about..
if statement bro..
- 1
Hey, Arun Tomar I didn't understand. Why not the value of age inserted in the scanner class is not used to compare?