Results 1 to 20 of 20
- 04-23-2008, 01:57 PM #1
[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.
- 04-23-2008, 02:55 PM #2
Do you need an simple example program that demonstrate these..??
sanjeev,संजीव
- 04-23-2008, 03:28 PM #3
Hey Zebra, here is something simple for you:
Output: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!"); } } } }
Java Code:Jamie knows Java!
Did this post help you? Please
me! :cool:
- 04-24-2008, 03:14 AM #4
Thanks so much! I will study this and tell you how I do on my next test.
+repLast edited by Zebra; 04-24-2008 at 03:23 AM.
I am a Java n00b.
- 04-24-2008, 10:16 AM #5
No problem Zerba.
Have you looked at the Sun Java Tutorials? Its a brilliant place to learn.
The Java™ TutorialsDid this post help you? Please
me! :cool:
- 04-24-2008, 10:29 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Why do you guys use the way like this,
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?Java Code:String[] name;
- 04-24-2008, 10:30 AM #7
Well said Eranga.
sanjeev,संजीव
- 04-24-2008, 10:33 AM #8
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:
- 04-24-2008, 11:05 AM #9
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 04-24-2008, 11:15 AM #10
Its just like in the main method.
Sometimes in books & tutorials you see it like this:
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:public static void main(String args[]) { }
Ill try to do that in the future to keep you purists happy! lolJava Code:String[]
Did this post help you? Please
me! :cool:
- 04-24-2008, 11:28 AM #11
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 04-24-2008, 01:50 PM #12
I have a question is the if statement an "if-then" in this code below...or just an if?
and what does the for-loop do in this code?Java Code:// If-then statement if (name[i] == "Alex") { System.out.println(name[i] + " knows Java!"); } } } }
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.
- 04-24-2008, 01:53 PM #13
Yeah its basically a if-then statement...
It means if the IF statement is true, THEN do something.
So if
(which is true)Java Code:name[i] == Alex
THEN
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.Java Code:System.out.println(name[i] + " knows Java!");
Thats what name.length means.Last edited by DonCash; 04-24-2008 at 02:14 PM.
Did this post help you? Please
me! :cool:
- 04-24-2008, 02:10 PM #14
Member
- Join Date
- Apr 2008
- Posts
- 2
- Rep Power
- 0
can someone help me out on how to install and use any database program with java. basically MS SQL
- 04-24-2008, 02:15 PM #15
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:
- 04-25-2008, 03:47 AM #16
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 05-02-2008, 02:15 PM #17
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.
- 05-02-2008, 02:17 PM #18
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:
- 05-02-2008, 07:48 PM #19
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.
- 05-03-2008, 03:46 AM #20
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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
-
Java Machine Learning Library 0.0.12
By JavaBean in forum Java SoftwareReplies: 0Last Post: 10-20-2007, 05:56 PM -
How to start learning Java
By hiranya in forum New To JavaReplies: 2Last Post: 06-28-2007, 02:55 PM -
Learning Activity Management System 2.0.3
By levent in forum Java SoftwareReplies: 0Last Post: 06-05-2007, 11:44 AM -
Learning Activity Management System 2.0
By levent in forum Java SoftwareReplies: 0Last Post: 05-16-2007, 05:02 AM -
Learning Tree Instructor Opportunities
By LearningTree in forum Jobs OfferedReplies: 0Last Post: 04-25-2007, 08:33 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks