|
|||
|
Java Code:
public class Test1{
public static void main(String[] args){
String[] names={"bob","jill","frank","stewart","charlie"};
for(String item: names){
System.out.println("This name in the array is " + item);
}
}
}
I guess it will come with time. |
|
||||
|
ah yeah I can see why you would think this code is more complicated when it actually isnt.
This is still a String array and for loop printing its content. Array values can be stored like this: Java Code:
String[] names={"bob","jill","frank","stewart","charlie"};
Java Code:
String[] name = new String[5] name[0] = "bob"; name[1] = "jill"; name[2] = "frank"; name[3] = "stewart"; name[4] = "charlie"; Java Code:
for(String item: names){
System.out.println("This name in the array is " + item);
}
|
|
|||
|
so the reason I thought the candidate program was hard was because of the fact that he used a different method of array?
would it be more beneficial to create a standard for loop and have it iterate over the length while I print the arrays? Last edited by Fendaril; 07-11-2008 at 01:49 PM. |
|
||||
|
Yeah the reason it looked hard was because they used a different method of array.
As far as im aware, there is no difference in performance between the for and for-each loop. But if you want to print the content of an array I would get used to learning the for-each loop as its more convenient and no doubt you will encounter it alot in the future. |
|
||||
|
Quote:
Spend some time to read through the Sun Java tutorials about Classes and Objects. Even if you have read it 5 times before, read it again. Lesson: Classes and Objects (The Java™ Tutorials > Learning the Java Language) You need to keep reading even if you don't understand. Each time it will gradually sink in more and more. Try to write code that will help you to understand. For example, try to pass a variable between 2 different classes.. I remember it took me a while to get my head around OOP too. The key really is just to keep writing code. |
|
|||
|
I havent done anything related to java in 2 days. I got so stressed out and just played games. I feel so incomplete so I am going to do something worthwhile.
Ok so I think I came upon a good project to start out with. I found out how to pass variables through different methods. What if I passed variables through methods like 'addition(i,j)' while taking input from the user. It does require me to jump a head a little bit but a calculator is something that is very easy to make. I could use the beautiful if-else ladder. The process I have to take to make it is a bit harder then in c++. Not comparing or anything. Last edited by Fendaril; 13-11-2008 at 01:37 PM. |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
LinkBacks (?)
LinkBack to this Thread: http://www.javaprogrammingforums.com/new-java/150-new-java-struggling-arrays.html
|
||||
| Posted By | For | Type | Date | |
| Java Programming Forums - JavaProgrammingForums.com | This thread | Refback | 04-11-2008 03:04 PM | |
|
100 most searched terms
Search Cloud
|
| "bad endpoint type" com.sun.xml.internal.messaging.saaj.soapexceptionimpl com.sun.xml.internal.messaging.saaj.soapexceptionimpl: bad endpoint type com.sun.xml.internal.messaging.saaj.soapexceptionimpl: java.security.privilegedactionexception com.sun.xml.internal.messaging.saaj.soapexceptionimpl: java.security.privilegedactionexception: com.sun.xml.internal.messaging.saaj.soapexceptionimpl: java.security.privilegedactionexception: com.sun.xml.internal.messaging.saaj.soapexceptionimpl: message send failed com.sun.xml.internal.messaging.saaj.soapexceptionimpl: message send failed com.sun.xml.messaging.saaj.soapexceptionimpl: java.security.privilegedactionexception com.sun.xml.messaging.saaj.soapexceptionimpl: java.security.privilegedactionexception: com.sun.xml.messaging.saaj.soapexceptionimpl: message send failed convert arraylist to map date_format_now eclipse shortcut keys ejb3 quartz java convert double to binary java forum java forums java jtextarea bold java jtextarea color java jtextarea font java jtextarea font size java programmer forum java programmers forum java programming forum java programming forums java read last line java read last line of file java sendkeys java.security.privilegedactionexception java.security.privilegedactionexception: com.sun.xml.internal.messaging.saaj.soapexceptionimpl java.security.privilegedactionexception: com.sun.xml.internal.messaging.saaj.soapexceptionimpl: bad response java.security.privilegedactionexception: com.sun.xml.internal.messaging.saaj.soapexceptionimpl: message send failed java.security.privilegedactionexception: com.sun.xml.messaging.saaj.soapexceptionimpl: message send failed javapf javaprogrammingforums jtextarea bold jtextarea font jtextarea font color jtextarea font size programing forums programming forums reset jcombobox saaj0008 saaj0008: bad response; bad request saaj0008: bad response; not found severe: saaj0008 severe: saaj0008: bad response; bad request severe: saaj0008: bad response; not found soap java.security.privilegedactionexception soapexceptionimpl: bad endpoint type textpad java |