<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'New to java' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'New to java' posted on the 'Java Beginners' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2012 Programmers Heaven</copyright>
    <pubDate>Thu, 09 Feb 2012 09:52:02 -0800</pubDate>
    <lastBuildDate>Thu, 09 Feb 2012 09:52:02 -0800</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>New to java</title>
      <link>http://www.programmersheaven.com/mb/java_beginners/410383/410383/new-to-java/</link>
      <description>I've never used Java before today so I'm really clueless about the possibilities and such, I've made a really simple math quiz and I'm wondering if there is a better way to make it have more questions other than adding each one manually.&lt;br /&gt;
&lt;br /&gt;
Is there anything that would let me massively condense the amount of code needed for say 30 questions, or any way to let the user input how many questions they want at the start and have that amount created?&lt;br /&gt;
&lt;br /&gt;
I'm guessing that's what Arrays are used for, but I haven't really been able to find any easy to follow articles on using them - I learn alot better by seeing a practical example and changing it through trial and error.&lt;br /&gt;
&lt;br /&gt;
Any help would be appreciated, below is what I have so far.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
import java.io.*; 
import java.util.*;

class Test2 {
  public static void main (String[] args) throws IOException {

    BufferedReader Answer = new BufferedReader
      (new InputStreamReader(System.in));

    int num1, num2, correct1, correct2, score;

    int a = (int)(5.0 * Math.random()) + 5;
    int b = (int)(5.0 * Math.random()) + 5;
    int c = (int)(5.0 * Math.random()) + 5;
    int d = (int)(5.0 * Math.random()) + 5;

    System.out.print ("What is " +a+ " * " +b+ "? ");
    System.out.flush(); 
    num1 = Integer.parseInt( Answer.readLine());

if(num1 == a * b) 
      {
        correct1 = 1;
      }
      else{
         correct1 = 0;
      }
      	
    System.out.print ("What is " +c+ " * " +d+ "? ");
    System.out.flush(); 
    num2 = Integer.parseInt( Answer.readLine());

if(num2 == c * d) 
      {
	correct2 = 1;
      }
      else
      {
         correct2 = 0;
      }
  
    score = correct1 + correct2; 
    System.out.println("You scored " + score + " out of 2.");
 } 
&lt;/pre&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/java_beginners/410383/410383/new-to-java/</guid>
      <pubDate>Sat, 05 Dec 2009 13:24:24 -0800</pubDate>
      <category>Java Beginners</category>
    </item>
    <item>
      <title>Re: New to java</title>
      <link>http://www.programmersheaven.com/mb/java_beginners/410383/410388/re-new-to-java/#410388</link>
      <description>You don't have to use an array.  You could get what you want with a loop.&lt;br /&gt;
&lt;br /&gt;
Here's some cleaner code.  Set numQuestions to whatever you want.  This little piece of code could ask 1000 questions by just adding 3 more characters to the code.&lt;br /&gt;
&lt;br /&gt;
It includes some helpful comments for users that get the questions wrong too.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
import java.util.*;

class Test2 {

private static String[] loserComments = new String[]
{
 "Loosseeerrr!!",
 "you SUCK!!",
 "dummb bum!!",
 "not the brightest.",
 "what an idiot!!!",
 "how could you get that wrong???"
};

  public static void main (String[] args) 
 {

    Scanner console = new Scanner(System.in);

    int num1, score=0;
    int numQuestions = 5;

  for (int i=0;i&amp;lt;numQuestions;i++)
  {

    int a = (int)(10.0 * Math.random());
    int b = (int)(10.0 * Math.random());

    System.out.print ("What is " +a+ " * " +b+ "? ");

    num1 = console.nextInt();

      if(num1 == a * b) 
      {
        score++;
      }
      else
      {
         System.out.println(loserComments[
          (int)(loserComments.length*Math.random())]);
      }

  }
    System.out.println("You scored " + score + " out of "+numQuestions+".");
 } 

}
&lt;/pre&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/java_beginners/410383/410388/re-new-to-java/#410388</guid>
      <pubDate>Sat, 05 Dec 2009 21:24:01 -0800</pubDate>
      <category>Java Beginners</category>
    </item>
  </channel>
</rss>
