Welcome to Dream.In.Code
Become a Java Expert!

Join 149,605 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,907 people online right now. Registration is fast and FREE... Join Now!




a way read strings in any combination

 
Reply to this topicStart new topic

a way read strings in any combination

Mastergeek666
12 Sep, 2007 - 01:32 PM
Post #1

D.I.C Head
Group Icon

Joined: 10 Aug, 2007
Posts: 120


Dream Kudos: 75
My Contributions
Hey I was just wondering if there is a way to do a
CODE
keyboard.readLine
were it reads the line in any combination. For example say I have the strings 1,2,3,4,5 and instead of just acknowledging the individual strings like just 1 I want it to read something like 54321 without me having to make that number a string. If you could help that would be great Thanks.
User is offlineProfile CardPM
+Quote Post

alpha02
RE: A Way Read Strings In Any Combination
12 Sep, 2007 - 02:05 PM
Post #2

D.I.C Addict
Group Icon

Joined: 20 May, 2006
Posts: 687


Dream Kudos: 850
My Contributions
If you mean "change the order of the digits in a number", this is impossible unless you use a mathematical operation. You need to make a string, then "sone string".toCharArray() to get the characters (char[]), then you can do anything you wish.
User is offlineProfile CardPM
+Quote Post

Mastergeek666
RE: A Way Read Strings In Any Combination
12 Sep, 2007 - 02:21 PM
Post #3

D.I.C Head
Group Icon

Joined: 10 Aug, 2007
Posts: 120


Dream Kudos: 75
My Contributions
QUOTE(alpha02 @ 12 Sep, 2007 - 03:05 PM) *

If you mean "change the order of the digits in a number", this is impossible unless you use a mathematical operation. You need to make a string, then "sone string".toCharArray() to get the characters (char[]), then you can do anything you wish.



Actually its like this i have
CODE
String[] integers = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"};
and what I'm trying to do is get it so that if you enter any number it will just use the strings above instead of having to make some ridiculous amount of strings.
User is offlineProfile CardPM
+Quote Post

alpha02
RE: A Way Read Strings In Any Combination
12 Sep, 2007 - 02:25 PM
Post #4

D.I.C Addict
Group Icon

Joined: 20 May, 2006
Posts: 687


Dream Kudos: 850
My Contributions
Maybe you are looking for something like:

CODE
String kb = keyboard.readLine;
for (int i=0; i<10; i++){
    if (integers[i].equals(kb) == true){
        System.out.println("Array offset "+i);
    }
}



This code looks if the entered character is an int. Is this what you're looking for?

User is offlineProfile CardPM
+Quote Post

Programmist
RE: A Way Read Strings In Any Combination
12 Sep, 2007 - 02:28 PM
Post #5

Four-letter word
Group Icon

Joined: 2 Jan, 2006
Posts: 1,250



Thanked: 11 times
Dream Kudos: 100
Expert In: Java

My Contributions
QUOTE(Mastergeek666 @ 12 Sep, 2007 - 03:21 PM) *

QUOTE(alpha02 @ 12 Sep, 2007 - 03:05 PM) *

If you mean "change the order of the digits in a number", this is impossible unless you use a mathematical operation. You need to make a string, then "sone string".toCharArray() to get the characters (char[]), then you can do anything you wish.



Actually its like this i have
CODE
String[] integers = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"};
and what I'm trying to do is get it so that if you enter any number it will just use the strings above instead of having to make some ridiculous amount of strings.

I'm not sure I see the point. You do know that Integers can be converted to Strings, yes? So, if someone entered a number, then you could just convert it to a String, rather than combining several decimal number Strings.

This post has been edited by Programmist: 12 Sep, 2007 - 02:29 PM
User is offlineProfile CardPM
+Quote Post

Mastergeek666
RE: A Way Read Strings In Any Combination
12 Sep, 2007 - 02:34 PM
Post #6

D.I.C Head
Group Icon

Joined: 10 Aug, 2007
Posts: 120


Dream Kudos: 75
My Contributions
QUOTE(alpha02 @ 12 Sep, 2007 - 03:25 PM) *

Maybe you are looking for something like:

CODE
String kb = keyboard.readLine;
for (int i=0; i<10; i++){
    if (integers[i].equals(kb) == true){
        System.out.println("Array offset "+i);
    }
}



This code looks if the entered character is an int. Is this what you're looking for?



Sort of what I'm looking for, Umm...OK, say that I have those strings and the program runs if you enter, 1,2,3,4,etc, I want it to instead of only being able to enter those numbers and work I want to be able to enter say 123, a mix of those numbers and work. Do you see what I'm saying? I want to just have those strings without having to count to say 54363 in numbers as strings. Sorry again if I'm not making any sense. Thanks for the help
User is offlineProfile CardPM
+Quote Post

Programmist
RE: A Way Read Strings In Any Combination
13 Sep, 2007 - 10:28 AM
Post #7

Four-letter word
Group Icon

Joined: 2 Jan, 2006
Posts: 1,250



Thanked: 11 times
Dream Kudos: 100
Expert In: Java

My Contributions
I can't speak for alpha02, but I still don't have a clear idea of what you want. Sorry. smile.gif

BTW, alpha02...integers[i].equals(kb) == true can be reduced to this integers[i].equals(kb). Think about it. true is always equal to true and false is never equal to true. smile.gif

This post has been edited by Programmist: 13 Sep, 2007 - 10:29 AM
User is offlineProfile CardPM
+Quote Post

alpha02
RE: A Way Read Strings In Any Combination
13 Sep, 2007 - 01:28 PM
Post #8

D.I.C Addict
Group Icon

Joined: 20 May, 2006
Posts: 687


Dream Kudos: 850
My Contributions
QUOTE(Programmist @ 13 Sep, 2007 - 02:28 PM) *

I can't speak for alpha02, but I still don't have a clear idea of what you want. Sorry. smile.gif

BTW, alpha02...integers[i].equals(kb) == true can be reduced to this integers[i].equals(kb). Think about it. true is always equal to true and false is never equal to true. smile.gif


I know, but putting "== true" is one of my programming habits, I don't know why. Anyway, you could use:

CODE
Scanner in = new Scanner(System.in);
String num = in.next();


This is what you might be looking for.
User is offlineProfile CardPM
+Quote Post

Mastergeek666
RE: A Way Read Strings In Any Combination
13 Sep, 2007 - 06:44 PM
Post #9

D.I.C Head
Group Icon

Joined: 10 Aug, 2007
Posts: 120


Dream Kudos: 75
My Contributions
QUOTE(alpha02 @ 13 Sep, 2007 - 02:28 PM) *

QUOTE(Programmist @ 13 Sep, 2007 - 02:28 PM) *

I can't speak for alpha02, but I still don't have a clear idea of what you want. Sorry. smile.gif

BTW, alpha02...integers[i].equals(kb) == true can be reduced to this integers[i].equals(kb). Think about it. true is always equal to true and false is never equal to true. smile.gif


I know, but putting "== true" is one of my programming habits, I don't know why. Anyway, you could use:

CODE
Scanner in = new Scanner(System.in);
String num = in.next();


This is what you might be looking for.



Thx for the help guys I think I got it what I need!

This post has been edited by Mastergeek666: 13 Sep, 2007 - 07:10 PM
User is offlineProfile CardPM
+Quote Post

Programmist
RE: A Way Read Strings In Any Combination
14 Sep, 2007 - 09:45 AM
Post #10

Four-letter word
Group Icon

Joined: 2 Jan, 2006
Posts: 1,250



Thanked: 11 times
Dream Kudos: 100
Expert In: Java

My Contributions
QUOTE(alpha02 @ 13 Sep, 2007 - 02:28 PM) *

I know, but putting "== true" is one of my programming habits, I don't know why...


It's not wrong, just redundant and redundant. smile.gif

QUOTE(Mastergeek666 @ 13 Sep, 2007 - 07:44 PM) *

Thx for the help guys I think I got it what I need!

So, what was your solution? I'm only curious because I think your solution will shed some light on what you were trying to do.

This post has been edited by Programmist: 14 Sep, 2007 - 09:44 AM
User is offlineProfile CardPM
+Quote Post

Mastergeek666
RE: A Way Read Strings In Any Combination
18 Sep, 2007 - 06:38 PM
Post #11

D.I.C Head
Group Icon

Joined: 10 Aug, 2007
Posts: 120


Dream Kudos: 75
My Contributions
QUOTE(Programmist @ 14 Sep, 2007 - 10:45 AM) *

QUOTE(alpha02 @ 13 Sep, 2007 - 02:28 PM) *

I know, but putting "== true" is one of my programming habits, I don't know why...


It's not wrong, just redundant and redundant. smile.gif

QUOTE(Mastergeek666 @ 13 Sep, 2007 - 07:44 PM) *

Thx for the help guys I think I got it what I need!

So, what was your solution? I'm only curious because I think your solution will shed some light on what you were trying to do.



Oh I changed my code completely to just check if you entered any number and then put it through my GCF code.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 11:56PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month