0

Hi I'm just beginner in Java and I don't undestand one thing what's the difference between this two codes:

System.out.println("Write a number: ");
int a = Integer.parseInt(sc.nextLine());

System.out.println("Write a number: ");
int b = sc.nextInt();

1 Answers1

0

In nextLine() if you input number values that it will consider as String. Then it is parsed to Integer and stored in int a

In nextInt() the entered numerical value is considered Int and stored in int b

Digvijaysinh Gohil
  • 1,002
  • 2
  • 10
  • 25