+ 9
long input=new Scanner(System.in).nextInt();
This line is correct.
3 Antworten
+ 3
Avinesh you doesn't understand my problem
I mean variable input is of long type and we're using nextInt instead of nextLong
Why doesn't it create any error
+ 1
Can you tell me why do you think this fail?
Scanner sc = new Scanner(System.in);
long num = sc.nextInt();
Here 'sc' is just a reference to the Scanner object, so you can use the Scanner object itself to call the nextInt() on it.
Both mean the same.
+ 1
๖ۣۜƊeⱥᖙpͥooͣlͫツ you should have made that clear in the question itself.
Anyways in Java you can store float in double without converting to double and similarly you can store integer in long type and this typecasting is implicit and taken care by the compiler.
But to do the other way, you must explicitly typecast it to respective types.