+ 9

long input=new Scanner(System.in).nextInt();

This line is correct.

13th May 2020, 9:56 AM
Reca Resu
Reca Resu - avatar
3 Réponses
+ 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
14th May 2020, 8:27 AM
Reca Resu
Reca Resu - avatar
+ 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.
13th May 2020, 10:07 AM
Avinesh
Avinesh - avatar
+ 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.
14th May 2020, 9:19 AM
Avinesh
Avinesh - avatar