Thread: Number in Java
View Single Post
Old Mar 24th, 2008, 12:30 AM   #4
RainMan
Newbie
 
Join Date: Mar 2008
Posts: 7
Rep Power: 0 RainMan is on a distinguished road
Re: Number in Java

The exact problem I am having is that I can't find out if there is a way to ask the user to enter a set of integers of the form 0...some integer say 10 in the form 0...10 and have java take it to mean all the integers from 0 to 10. as in 0 1 2 3 4 5 6 7 8 9 10 . this is common notation in the math world.

the closest approximation i can think of in code
java Syntax (Toggle Plain Text)
  1. System.out.print( "please enter the first and last integers of the set in the form a...b: ");
  2. something in here that actually takes the set and passes it to an array without needing several hundred or thousand variables declared.
and then have java put those values into an array. rather than have a set with 1000 integers in it and having something like
java Syntax (Toggle Plain Text)
  1. System.out.print(" please first integer: ");
  2. int a = input.nextInt();
  3.  
  4. System.out.print("please enter second integer: ");
  5. int b = input.nextInt();
  6. .
  7. .
  8. .
  9. .
  10. .
  11. 1000 times


What i came up with is entering the first value and then the last value and trying to put it into a for loop with an array.

java Syntax (Toggle Plain Text)
  1. public double setAlength( double al )
  2. {
  3. al = last - first;
  4. }
  5. public double setGroupArray( double garray[])
  6. {
  7.  
  8. groupArray = garray;
  9.  
  10. for( double counter = 0; counter < alength; counter++)
  11. {
  12. garray[counter] = first + counter;
  13.  
  14. }

this seems clumsy though and i don't really think i have it set up right yet, a big problem with this is that some algebraic groups do not start at 0 or a positive number which would cause issues when you get into the negative numbers. However i'm not asking you to tell me how to write the code, i'm asking if anyone knows if there is something in java to accept entering mathematical sets in this nature..and if there is then where i might find out about it. Any critiques and suggestions of the code will be accepted in a gracious manner if you feel like offering them..but I don't ask people to do my work for me. i will succeed or fail on my own. The string tokenizer will work the data after it's been input into the program, but i'm trying to change the way the data is input into the program...if i'm understanding what i read about it correctly, if i'm not feel free to say so. If i was just going to confine it to easily entered sets for groups it wouldn't be an issue, but easily entered sets for groups are easily validated or invalidated by hand. i don't know about anyone else but a program that is supposed to make life easier that makes you input several thousand numbers doesn't really seem to be worth it.
__________________
Preposterous amounts of testosterone....Preposterone - powerthirst

Last edited by RainMan; Mar 24th, 2008 at 12:59 AM.
RainMan is offline   Reply With Quote