Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old Jan 11th, 2007, 1:58 PM   #1
fresher
Newbie
 
Join Date: Dec 2006
Posts: 13
Rep Power: 0 fresher is on a distinguished road
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.
fresher is offline   Reply With Quote
Old Jan 11th, 2007, 2:30 PM   #2
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Possibly:
if ("".equals(network))
Or perhaps:
if ("".equals(network.trim()))
Arevos is offline   Reply With Quote
Old Jan 11th, 2007, 2:43 PM   #3
fresher
Newbie
 
Join Date: Dec 2006
Posts: 13
Rep Power: 0 fresher is on a distinguished road
Quote:
Originally Posted by Arevos View Post
Possibly:
if ("".equals(network))
Or perhaps:
if ("".equals(network.trim()))

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
fresher is offline   Reply With Quote
Old Jan 11th, 2007, 2:57 PM   #4
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Quote:
Originally Posted by fresher View Post
thanks for your reply but is network.trim() a java function
Yes, and a quick Google or a look at the Sun javadocs would tell you all about it

Quote:
Originally Posted by fresher View Post
and what is the meaning of " ".equals..... please? a little comment will be perfect. thanks in advance
To check whether two strings, a and b, are equal, you'd use the following code:
a.equals(b)
If b is null, then the above expression returns false. If a is null, then an exception is raised, because you can't have null.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
Arevos is offline   Reply With Quote
Old Jan 11th, 2007, 2:59 PM   #5
fresher
Newbie
 
Join Date: Dec 2006
Posts: 13
Rep Power: 0 fresher is on a distinguished road
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
fresher 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
User input jayme C++ 38 Nov 25th, 2005 8:27 PM
FiveDigit + RandomeNumber Game. TecBrain Java 0 Nov 18th, 2005 3:53 PM
User Input for Number Format ericelysia1 Java 0 Jul 21st, 2005 4:41 PM
Problem read'ing from file and user input jmsilver Bash / Shell Scripting 3 May 20th, 2005 3:35 PM
Instant Messaging App Help AusTex C 0 Apr 27th, 2005 5:52 PM




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

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