-2
Scanner sc = new Scanner(System.in);
    System.out.println("Enter the details given below.");
    System.out.println("Name:");name=sc.next();
    sc.next();

    System.out.println("Phone/mobile number:+91 ");phone_num=sc.nextLong();
    System.out.println("Home Address:");address=sc.next();
    sc.next();
    System.out.println("Pincode:");pincode=sc.nextLong();
    System.out.println("E-mail address:");e_mail=sc.next();
    sc.next();

this code snippet does not let me take the input to the pincode variable.

James Z
  • 11,838
  • 10
  • 25
  • 41
  • 3
    Read the javadocs fo the `next()` and `nexlLine()` methods carefully. Then look at your code. Repeat, until you have figured it out!! This is a debugging problem ... and you need to work it out for yourself. Otherwise you won't be able to do this thing in an exam or a job interview. – Stephen C Aug 12 '17 at 04:11

1 Answers1

0

I see three things you need to change.

  • Get rid of all those extra sc.next() lines that don't assign the value to a variable. There's no reason why you'd want to read in an extra token at those points.
  • Consider using sc.nextLine() instead of sc.next() to read in a String, so that if there are any spaces in the input, they become part of the String.
  • Read the answers to this question which explain a problem you might run into after the call to sc.nextLong() and how to deal with it.
Dawood ibn Kareem
  • 68,796
  • 13
  • 85
  • 101