Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 23rd, 2008, 5:00 PM   #1
RainMan
Newbie
 
Join Date: Mar 2008
Posts: 7
Rep Power: 0 RainMan is on a distinguished road
Number in Java

Is there any way to have a user input a set of numbers in the form of 0...whatever. i.e like 0...100 and have java take every number between 0 to 100.? I'm asking because as a personal project I am trying to write a program that will evaluate if a set is an algebraic group or not. I'm aware that this has probably been done and better than I will be able to do it but i think it will be a productive exercise for me. I would like the user to be able to enter a set of any size without having to enter in each individual number. Especially since you can have groups that are infinitely large. I haven't figured out how to deal with infinite groups yet. any thoughts on that would be a good thing too.

What I have come up with idea wise so far is to use an array to deal with the numbers, however i only know how to pass the array elements as arguments that the user has to input individually. Then the operations are just simple comparisons and evaluations.

Another thought I have had is to make it so that the program will determine what sets of the entered values are groups, but that involves getting the code to throw out values and keep others to return them, which might be a bit over my head at this point. I am really just focusing on getting the basic program going right now any pointers in the right direction would be appreciated.
__________________
Preposterous amounts of testosterone....Preposterone - powerthirst
RainMan is offline   Reply With Quote
Old Mar 23rd, 2008, 11:17 PM   #2
Grich
Professional Programmer
 
Grich's Avatar
 
Join Date: Sep 2007
Location: Sydney - Australia
Posts: 329
Rep Power: 2 Grich is on a distinguished road
Re: Number in Java

Look into the String Tokenizer. It will divide the input string from the user, then you can do whatever you want with the data.
__________________
SYNTAX ERROR ...
Grich is offline   Reply With Quote
Old Mar 23rd, 2008, 11:47 PM   #3
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 936
Rep Power: 4 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Re: Number in Java

You'll get more help if you're more specific about the problem you are having. Decide on the format you will require, show sample input strings, and how you are trying to process them.
titaniumdecoy is offline   Reply With Quote
Old Mar 24th, 2008, 1: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 1:59 AM.
RainMan is offline   Reply With Quote
Old Mar 24th, 2008, 3:14 AM   #5
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 936
Rep Power: 4 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Re: Number in Java

Consider that the number of elements in the array will be abs(first-last) + 1.

I will try to keep this fairly vague since it seems you want to solve this problem yourself. For the loop, I would suggest using two variables as counters: one as an index into the array from 0 to the number of elements in the array - 1; and another for counting from the first to the last number in the set. (There are, as always, numerous ways to achieve the same goal.)

As for allowing user input in the format a...b, you could use StringTokenizer or Pattern and Matcher for regular expression matching.
titaniumdecoy is offline   Reply With Quote
Old Mar 31st, 2008, 8:38 PM   #6
Fall Back Son
Professional Programmer
 
Join Date: Oct 2006
Posts: 311
Rep Power: 3 Fall Back Son is on a distinguished road
Re: Number in Java

Quote:
Originally Posted by RainMan View Post
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.
There are multiple ways you can do this.

If you don't insist on using that format, you can accomplish the task easily by requesting the user to enter the first and last numbers in the set. Or you can let them enter it however they want and just treat the set as the values between the first value they entered and the last value they entered. You don't have to "deal with" infinite ranges (in most applications) because for any given value, you can just check if its between the two values the user entered -- if so, its part of the set.

If you do insist on using that format, look into the classes Matcher and Pattern. Reading about Regular Expressions will be particularly helpful to you. Regular Expressions allow you to match input based on a pattern... which is exactly what you want to do. Here's the link to a tutorial from Sun... I've read it myself, its very helpful:

http://java.sun.com/docs/books/tutor...gex/index.html
Fall Back Son is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Programming with Java: Tutorial ReggaetonKing Java 7 May 20th, 2008 11:58 AM
Special browser in Java (Project) stalefish Java 3 Feb 9th, 2008 5:22 PM
Guess a Number 3n! C++ 7 Dec 2nd, 2007 4:38 AM
Java programmers, game developers, artists, be ware! RPG game team is recruiting! atcomputers.us Paid Job Offers 7 Sep 25th, 2005 8:25 PM
objects in java cwl157 Java 6 Mar 2nd, 2005 2:06 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:56 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC