java - Unable to get one specific input from scanner -


i newbie. know code messy. working on adding comments , such.

    try // customer's address     {     system.out.println("\nplease type in shipping address.");     system.out.println ("this way can receive have ordered.");     system.out.println ("in format: street, city, state, zipcode\n");     customeraddress = input.nextline();     }     catch (exception e)             {                 system.out.println("you need enter in address.");             }      try // customer's telephone number     {         system.out.println("please enter in telephone number:\n");         phonenumber = input.nextline();     }     catch (exception e)     {         system.out.println("you need enter in phone number.");     } 

i able input phonenumber program seems skip right on customeraddress input.

below in command prompt. notice able input data under telephone number, did not chance put in address section.

please type in shipping address.
way can receive have ordered.
in format: street, city, state, zipcode

please enter in telephone number:

123457890

are there logic errors causing skip over?

if reading more data, scaner input.nextint(); read 1 int. 1 solution add input.nextline(); , should work.

solution 2:

use bufferedreader;

        bufferedreader bufferread = new bufferedreader(new inputstreamreader(system.in));          try{             system.out.println("\nplease type in shipping address.");             system.out.println ("this way can receive have ordered.");             system.out.println ("in format: street, city, state, zipcode\n");              customeraddress = bufferread.readline();         }catch (exception e){             system.out.println("you need enter in address.");         }          try {              system.out.println("please enter in telephone number:\n");              phonenumber =  bufferread.readline();         }catch (exception e){              system.out.println("you need enter in phone number.");         }             system.out.println(customeraddress + " " + phonenumber); 

see if output bufferedreader.

hope helps.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -