Results 1 to 20 of 20
  1. #1
    Zebra's Avatar
    Zebra is offline Member
    Join Date
    Apr 2008
    Location
    Louisville, Indiana/Kentucky
    Posts
    64
    Rep Power
    0

    Default [SOLVED] Need a program for learning purposes.

    I need a program that contains a loop, if-then, and an array. If somebody can come up with any program with all of those it would be greatly appreciated. It doesn't matter what it is about. Try to keep it simple and not to advanced code. I need it to study. Thanks.
    I am a Java n00b.

  2. #2
    sanjeevtarar's Avatar
    sanjeevtarar is offline Senior Member
    Join Date
    Apr 2008
    Location
    Jaipur(India)
    Posts
    318
    Rep Power
    7

    Default

    Do you need an simple example program that demonstrate these..??
    sanjeev,संजीव

  3. #3
    DonCash's Avatar
    DonCash is offline Moderator
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    240
    Rep Power
    8

    Default

    Hey Zebra, here is something simple for you:

    Java Code:
    public class Zebra {
    
    	public static void main(String[] args) {
    		
    		// Declaring the array
    		String name[];
    		name = new String[5];
    		
    		// Setting the array values
    		name[0] = "Bill";
    		name[1] = "Mark";
    		name[2] = "Steve";
    		name[3] = "Craig";
    		name[4] = "Jamie";
    		
    		// For loop
    		for (int i = 0; i < name.length; i++)
    		{
    			// If-then statement
    			if (name[i] == "Jamie")
    			{
    				System.out.println(name[i] + " knows Java!");
    			}
    		}
    	}
    }
    Output:

    Java Code:
    Jamie knows Java!
    Did this post help you? Please me! :cool:

  4. #4
    Zebra's Avatar
    Zebra is offline Member
    Join Date
    Apr 2008
    Location
    Louisville, Indiana/Kentucky
    Posts
    64
    Rep Power
    0

    Default

    Thanks so much! I will study this and tell you how I do on my next test.

    +rep
    Last edited by Zebra; 04-24-2008 at 03:23 AM.
    I am a Java n00b.

  5. #5
    DonCash's Avatar
    DonCash is offline Moderator
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    240
    Rep Power
    8

    Default

    No problem Zerba.

    Have you looked at the Sun Java Tutorials? Its a brilliant place to learn.

    The Java™ Tutorials
    Did this post help you? Please me! :cool:

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Why do you guys use the way like this,

    Java Code:
    String name[];
    Why don't you use,

    Java Code:
    String[] name;
    Because, in my suggestion way anyone can easily say that name is a reference to String array object. Make more sense with other primitives, isn't it?

  7. #7
    sanjeevtarar's Avatar
    sanjeevtarar is offline Senior Member
    Join Date
    Apr 2008
    Location
    Jaipur(India)
    Posts
    318
    Rep Power
    7

    Default

    Well said Eranga.
    sanjeev,संजीव

  8. #8
    DonCash's Avatar
    DonCash is offline Moderator
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    240
    Rep Power
    8

    Default

    Suppose its however you learnt it. I tend to do it that way round because thats how I was taught. Its habbit now!

    Both ways work fine so its personal preference...
    Did this post help you? Please me! :cool:

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Quote Originally Posted by DonCash View Post
    Both ways work fine so its personal preference...
    Yes Don, it's true. Both way is fine. But I'm not courage to use that way. :)

  10. #10
    DonCash's Avatar
    DonCash is offline Moderator
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    240
    Rep Power
    8

    Default

    Its just like in the main method.

    Sometimes in books & tutorials you see it like this:

    Java Code:
    public static void main(String[] args) {
    }
    And sometimes you see it like this:

    Java Code:
    public static void main(String args[]) {
    }
    Suppose the correct convention is to have it as:

    Java Code:
    String[]
    Ill try to do that in the future to keep you purists happy! lol
    Did this post help you? Please me! :cool:

  11. #11
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Sure Don, I have seen both of that way. :) But pal, different people get use of with different coding styles.

    Quote Originally Posted by DonCash View Post
    Ill try to do that in the future to keep you purists happy! lol
    Always :p

  12. #12
    Zebra's Avatar
    Zebra is offline Member
    Join Date
    Apr 2008
    Location
    Louisville, Indiana/Kentucky
    Posts
    64
    Rep Power
    0

    Default

    I have a question is the if statement an "if-then" in this code below...or just an if?

    Java Code:
    // If-then statement
    			if (name[i] == "Alex")
    			{
    				System.out.println(name[i] + " knows Java!");
    			}
    		}
    	}
    }
    and what does the for-loop do in this code?

    Java Code:
    //the for loop
    		for (int i = 0; i < name.length; i++)
    		{
    			//the If-then statement
    			if (name[i] == "Alex")
    			{
    				System.out.println(name[i] + " knows Java!");
    			}
    		}
    	}
    }
    Last edited by Zebra; 04-24-2008 at 01:56 PM.
    I am a Java n00b.

  13. #13
    DonCash's Avatar
    DonCash is offline Moderator
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    240
    Rep Power
    8

    Default

    Yeah its basically a if-then statement...

    It means if the IF statement is true, THEN do something.

    So if

    Java Code:
    name[i] == Alex
    (which is true)

    THEN

    Java Code:
    System.out.println(name[i] + " knows Java!");
    The for loop is looping through all the array values. It starts at 0 and loops for as many values as there are in the 'name' array.

    Thats what name.length means.
    Last edited by DonCash; 04-24-2008 at 02:14 PM.
    Did this post help you? Please me! :cool:

  14. #14
    iykepiccolo is offline Member
    Join Date
    Apr 2008
    Posts
    2
    Rep Power
    0

    Default

    can someone help me out on how to install and use any database program with java. basically MS SQL

  15. #15
    DonCash's Avatar
    DonCash is offline Moderator
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    240
    Rep Power
    8

    Default

    iykepiccolo - Please don't post an unrelated question here!!! Start a new thread. Thats what these forums are for.
    Did this post help you? Please me! :cool:

  16. #16
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Quote Originally Posted by DonCash View Post

    The for loop is looping through all the array values. It starts at 0 and loops for as many values as there are in the 'name' array.
    In further explanation, array element start indexing from 0. So the last index is (number_of_array_elements - 1). This is common for more languages. ;)

  17. #17
    Zebra's Avatar
    Zebra is offline Member
    Join Date
    Apr 2008
    Location
    Louisville, Indiana/Kentucky
    Posts
    64
    Rep Power
    0

    Default

    Thanks guys.

    Can somebody kindly make a little more advanced program with the same requirements. Please if you have time.
    I am a Java n00b.

  18. #18
    DonCash's Avatar
    DonCash is offline Moderator
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    240
    Rep Power
    8

    Default

    Zebra, using the code above, you should try to program something yourself. All the basics are there... See what you can come up with and post back here!! We will help you if you get stuck.
    Did this post help you? Please me! :cool:

  19. #19
    Zebra's Avatar
    Zebra is offline Member
    Join Date
    Apr 2008
    Location
    Louisville, Indiana/Kentucky
    Posts
    64
    Rep Power
    0

    Default

    Ok nevermind. It was a study guide for my friend. S, if somebody could make one then it would be appreciated. thanks.
    I am a Java n00b.

  20. #20
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Ok, what you mean an advanced program. What you expecting there.

    As far I believe, this is very very simple code. Actually I don't like to say it as an application either. How about real world application. May be a server application which is able to handle millions of clients in a second...

    Anyway, clarify more what you are looking for?

Similar Threads

  1. How to start learning Java
    By hiranya in forum New To Java
    Replies: 12
    Last Post: 01-13-2014, 09:47 AM
  2. Java Machine Learning Library 0.0.12
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 10-20-2007, 05:56 PM
  3. Learning Activity Management System 2.0.3
    By levent in forum Java Software
    Replies: 0
    Last Post: 06-05-2007, 11:44 AM
  4. Learning Activity Management System 2.0
    By levent in forum Java Software
    Replies: 0
    Last Post: 05-16-2007, 05:02 AM
  5. Learning Tree Instructor Opportunities
    By LearningTree in forum Jobs Offered
    Replies: 0
    Last Post: 04-25-2007, 08:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •