KnowledgeBoat Logo
|

Computer Applications

Raj was asked to accept the phone number which has 10 digits, using the appropriate method of Scanner class. Which of the following statement he must choose?

  1. Ob.nextInt()
  2. Ob.nextDouble()
  3. Ob.nextLong()
  4. Ob.next().chatAt(0)

Input in Java

3 Likes

Answer

Ob.nextLong()

Reason — Raj must use Ob.nextLong() because a 10-digit phone number exceeds the range of the int data type. The long data type can handle larger values, making it suitable for storing 10-digit numbers.

Answered By

2 Likes


Related Questions