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

14th Jun 2017, 11:25 AM
suryapoojary
suryapoojary - avatar
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); } }
14th Jun 2017, 12:43 PM
Nikolay Nachev
Nikolay Nachev - avatar
+ 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 😃
14th Jun 2017, 3:34 PM
Nikolay Nachev
Nikolay Nachev - avatar
+ 5
search Q&A there are many threads about that...
14th Jun 2017, 4:42 PM
Nikolay Nachev
Nikolay Nachev - avatar
+ 2
@Nikolay..it's still throwing errors..please check the updated code above.
14th Jun 2017, 3:11 PM
suryapoojary
suryapoojary - avatar
+ 1
thanks @Nikolay
14th Jun 2017, 4:12 PM
suryapoojary
suryapoojary - avatar
+ 1
How to gain xps faster ..I feel I'm crawling at a snail's pace :D
14th Jun 2017, 4:36 PM
suryapoojary
suryapoojary - avatar