Hello All, This is my opinion.
When the user enters an integer then hits "Enter". Two things have just been entered: the integer and a "newline" which is "\n". The method you are calling "netxtIn()" , it only reads in a integer, and then push a "newline" into next input stream. You can use this code: If(in.hasNextInt()){ myInt=in.nextInt(); }else{ If(in.hasNext()){ myStr=in.next; } From: javaprogrammingwithpassion@googlegroups.com [mailto:javaprogrammingwithpass...@googlegroups.com] On Behalf Of Olukosi, Olanrewaju Temitope Sent: Tuesday, November 16, 2010 1:42 AM To: javaprogrammingwithpassion@googlegroups.com Subject: [java programming] Java Error using Scanner(System.in) Hello All, I really need your help here. I tried running this code but was having problem with the Scanner method. When it gets to the second input, it skips to the third one. I mean when it gets to tName, it only prints the System.out.print statement and then prints the next statement without giving the prompt input for the former statement. Kindly help check what I am getting wrong. Help guys. import java.util.Scanner; public class MineClass { private static int tNum, tMM, noQ; private static String tName, tFName, tIMode; private static double [] quizMark; /* * This method reads in all the values that will be needed for the program. */ public static void main(String[] args){ Scanner in = new Scanner(System.in); System.out.print("TNNo: "); tNum = in.nextInt(); System.out.println("LFN: "); tName = in.nextLine(); System.out.println("TFN: "); tFName = in.nextLine(); System.out.print("IMM: "); tIMode = in.nextLine(); System.out.print("What To Cal?: "); noQ = in.nextInt(); quizMark = new double [noQ]; for (int a=0; a<noQ; a++){ System.out.print("The House No " + (a+1) +": "); quizMark[a] = in.nextDouble(); } System.out.println("Calsk: "); tMM = in.nextInt(); } } Regards -- DISCLAIMER This message contains privileged and confidential information and is intended only for the individual named. If you are not the intended recipient you should not disseminate, distribute, store, print, copy or deliver this message. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail and any attachments from your system. E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message which arise as a result of e-mail transmission. Thank you -- Tope Olukosi -- To post to this group, send email to javaprogrammingwithpassion@googlegroups.com To unsubscribe from this group, send email to javaprogrammingwithpassion+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/javaprogrammingwithpassion?hl=en -- To post to this group, send email to javaprogrammingwithpassion@googlegroups.com To unsubscribe from this group, send email to javaprogrammingwithpassion+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/javaprogrammingwithpassion?hl=en