We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
arrays (Read 878 times)
arrays
Oct 11th, 2007, 8:45pm
 
Hi everyone,
I am new to java.
I have a question?
How can I store in to an array the values that the user enter, so later I can compare the two sets of array that the user enter.
Thanks
Re: arrays
Reply #1 - Oct 12th, 2007, 4:57am
 
I feel that your question above needs a little more specific explanation about what exactly you want to do...
Re: arrays
Reply #2 - Oct 12th, 2007, 5:40am
 
Ok, the user needs to enter two sets, then main will call another class named IntergerSet where both sets are going to be compered.
Therefore I need to store the sets of values in two different sets.

This is what I have till know:

import java.util.Scanner;
public class UniversalSet
{
public static void main(String[] args)
{
Scanner input = new Scanner (System.in);

System.out.println("Welcome to the" +
                                " Universal Set\n");
     
   System.out.print("This program is going to find "  
                + "the union or intersection of any two "
                + "sets you enter\nPlease enter how many "
                + "values on set 1: ");
   int value1 = input.nextInt();
   
   System.out.print("Now please enter the first "
                + "set: ");
   for(int i=0; i<=value1 ;i++)
   {
//cannot find symbol method parseInt(int)->
             int userSetArray1[] = Integer.parseInt
                                      (userSetArray1[i]);
   }
   
   System.out.print("Please how many values on set "
                + "2: ");
   int value2 = input.nextInt();
   
   System.out.print("Now enter the second set: ");
   for(int i=0; i<=value2 ;i++)
   {
//cannot find symbol method parseInt(int)->
             int userSetArray2[] = Integer.parseInt
                                      (userSetArray2[i]);
   }
   
//cannot find symbol variable userSetArray1 and
//userSetArray1->  
       IntergerSet elementSet = new IntergerSet
                           (userSetArray1, userSetArray2);
   }
}
Re: arrays
Reply #3 - Oct 12th, 2007, 9:48am
 
java.util.Scanner won't work in a Processing Sketch. you'll have to listen to keyboard input using keyPressed() functions (http://processing.org/learning/basics/keyboard.html) or use extra librairies such as ControlP5 which provide textfields for user input:
http://www.sojamo.de/controlP5/
Re: arrays
Reply #4 - Oct 12th, 2007, 12:39pm
 
more important, it looks like you're just writing java code... processing isn't a particularly good environment for writing straight java code, and using System.in/System.out (or Scanner for that matter). processing is designed for building visual things and interactive works, so doing terminal-based stuff isn't gonna be fun.
Page Index Toggle Pages: 1