![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Dec 2006
Posts: 13
Rep Power: 0
![]() |
accepting user input
Hi all, i've this code below which prompts a user to select from a list of ip addresses.e.g 192.168.2.1....etc. Now i wona modify this code so that if the machine on which the program is run has a different network part (192.168.2.) then I can prompt the user to enter their network ID e.g (148.145.23.) then increment the last bit using a for loop. Anyone able to help me out pls? thanks in advance
I have added this block of code below in order to do this but it doesnt work:
System.out.print("Enter your network part or hit enter to proceed: ");
String network = in.readString();
//test
System.out.println(network);
//if enter is pressed - same network
if (network == null)
{
System.out.print("SELECT A MACHINE TO VIEW FROM LIST: ");
int choice = in.readInteger();
}
else
{
//pass new network part to ip string variable
ip = network;
}nb: this code is part of my previous post on ' passing a string to a variable.....' click here to view full code:http://www.programmingforums.org/for...-variable.html any help appreciated. |
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
Possibly:
if ("".equals(network))if ("".equals(network.trim())) |
|
|
|
|
|
#3 | |
|
Newbie
Join Date: Dec 2006
Posts: 13
Rep Power: 0
![]() |
Quote:
thanks for your reply but is network.trim() a java function and what is the meaning of " ".equals..... please? a little comment will be perfect. thanks in advance |
|
|
|
|
|
|
#4 | |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
Yes, and a quick Google or a look at the Sun javadocs would tell you all about it
Quote:
a.equals(b) So when comparing a string whose value could possibly be null (i.e. network), against a string whose value cannot be null (i.e. ""), then it's best to have the string that cannot be null as the one on the left, and the string that can be null on the right. "".equals(stringThatMightBeNull) // false when null
stringThatMightBeNull.equals("") // error when null |
|
|
|
|
|
|
#5 |
|
Newbie
Join Date: Dec 2006
Posts: 13
Rep Power: 0
![]() |
Also Arevos the 'if (" ".equals(network))' works if enter is pressed but the else part doesnt work if a network address is entered. In otherwords when the network part is entered, the switch statement is not executed. pls help me out. thanks in advance
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| User input | jayme | C++ | 38 | Nov 25th, 2005 7:27 PM |
| FiveDigit + RandomeNumber Game. | TecBrain | Java | 0 | Nov 18th, 2005 2:53 PM |
| User Input for Number Format | ericelysia1 | Java | 0 | Jul 21st, 2005 3:41 PM |
| Problem read'ing from file and user input | jmsilver | Bash / Shell Scripting | 3 | May 20th, 2005 2:35 PM |
| Instant Messaging App Help | AusTex | C | 0 | Apr 27th, 2005 4:52 PM |