Java

Moderators: zibadian
Number of threads: 7641
Number of posts: 17980

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

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])+ "]");
}
}
              



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 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.
Operated by CommunityHeaven, a BootstrapLabs company.