0
What am i doing wrong in this java code?
my java code is throwing error ..please help https://code.sololearn.com/coZ3xkkidsop/?ref=app
6 ответов
+ 10
you can't have two scanners, should be like this:
import java.util.Scanner;
public class Program{
public static void main(String[]args){
String name;
int age;
System.out.println("Whats your name?");
Scanner sc = new Scanner(System.in);
name = sc.nextLine();
System.out.println("Whats your age?");
age = sc.nextInt();
System.out.printf("Hi %s , you are %d years old",name,age);
}
}
+ 8
works fine with me. Most probably you don't enter the input in the "correct" way. Code Playground is a bit strange in that. Your code requires 2 inputs, you have to provide them on separate lines at the beginning then they will be fed to the program when needed. In other words when asked for input I need to enter:
-------------
Nikolay
39
------------
In the same dialog 😃
+ 5
search Q&A there are many threads about that...
+ 2
@Nikolay..it's still throwing errors..please check the updated code above.
+ 1
thanks @Nikolay
+ 1
How to gain xps faster ..I feel I'm crawling at a snail's pace :D