Looking for a hosted bug/issue tracker? Try our hosted development tools.

Java

Moderators: zibadian
Number of threads: 7175
Number of posts: 17129

This Forum Only
Post New Thread

Report
Scanner class = scn.next() Posted by javacoffee on 9 Nov 2009 at 8:22 PM
Hi there,
I am supposed to do a randomization of questions and the user answer them.

An example would be what does IE stands for:
the user must enters Internet Explorer. and it's correct.

However, in my programme, whenever the user enters "Internet Explorer" or any other string that has space, my program could not detect the correct answer. and it will loop 2 times depending on the String after the space the user entered. Example, Internet Explorer will loop 2 questions out.


Here is my source codes:
System.out.print("Ans: ");
     answer = scn.next();
  for (int num = 0; num < array.length; num++)
  {
  if (answer.toLowerCase().equals(array[num])
  {	
       accPoints += 20;
   System.out.println("Correct! You have " + accPoints + " points now!");
                     
 }
else 
 {
correct = false;
if (num ==0)
System.out.println("Incorrect! The answer is [" + array[num])+ "]");
}
}
              



 
Popular resources and forums for programmers on Programmersheaven.com
Assembly, Basic, C, C#, C++, Delphi, Java, JavaScript, Pascal, Perl, PHP, Python, Ruby, Visual Basic
© Copyright 2009 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Publisher: Lars Hagelin. Read the latest words from the publisher here.
Be the first to sign up for Lars Hagelin’s In-depth Outsourcing Newsletter here.
bootstrapLabs Logo A bootstrapLabs project.