Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: math quiz program

  1. #1
    Junior Member
    Join Date
    Oct 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default math quiz program

    import java.io.*;
    import java.lang.*;
    import java.util.Random;
    import java.math.*;
     
     
     
    public class first{
        public static void main(String args[])throws IOException{
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
     
            System.out.println("Mathematical Operations Drill");
            System.out.println("1.Practice");
            System.out.println("2.Challenge");
            System.out.println();
            System.out.println("Enter choice:");
            int choice=Integer.parseInt(br.readLine());
            System.out.println("Number of items:");
            int items=Integer.parseInt(br.readLine());
     
            generator.rangen(items);
        }
     
     
    public static class generator extends first{
    public static void rangen(int items){
        Random rand = new Random();
    	for(int counter=1; counter<items;counter++)
            {
    	int x=1+rand.nextInt(100);
    	int y=1+rand.nextInt(100);
            int z=1+rand.nextInt(4);
            switch(z){
                case 1:System.out.println(+x+"+"+y+"=");break;
                case 2:System.out.println(+x+"-"+y+"=");break;
                case 3:System.out.println(+x+"*"+y+"=");break;
                case 4:System.out.println(+x+"/"+y+"=");break;
                }
            }
            }
    }
    }

    How can I store the user's answers into an array? pls help.


  2. #2
    Member
    Join Date
    Oct 2009
    Posts
    52
    Thanks
    0
    Thanked 6 Times in 5 Posts

    Default Re: math quiz program

    What type are the answers? Are they integers or Strings?

    Here is an example of creating a array of Strings and an array ing ints. Each of them can have five elements in them.
    [FONT="Courier New"]String[] strArray = new String[5];
    int[] intARray = new int[5][/FONT]
    Then, to add stuff to an array, you do this:
    [FONT="Courier New"]strArray[0] = "first";
    strArray[1] = "more stuff";[/FONT]
    Last edited by helloworld922; October 23rd, 2009 at 10:32 AM.

Similar Threads

  1. Math in Java?
    By [Kyle] in forum Java Theory & Questions
    Replies: 3
    Last Post: September 23rd, 2009, 12:21 PM