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!
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.
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.
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.
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.
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.
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
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
I can't speak for alpha02, but I still don't have a clear idea of what you want. Sorry.
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.
This post has been edited by Programmist: 13 Sep, 2007 - 10:29 AM
I can't speak for alpha02, but I still don't have a clear idea of what you want. Sorry.
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.
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();
I can't speak for alpha02, but I still don't have a clear idea of what you want. Sorry.
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.
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