Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-21-2008, 03:02 PM
Zebra's Avatar
Member
 
Join Date: Apr 2008
Location: Louisville, Indiana/Kentucky
Posts: 64
Zebra is on a distinguished road
[SOLVED] Arrays/for-loops (easy) need help.
Hey I am suppose to rewrite the following code but make it so that the array is initialized on one line of code and a loop is used to display for the results.

Code:
class OneDimensionArray { public static void main(String args[]) { // Declare and allocate space int myarray[] = new int[4]; // Initialize elements myarray[0] = 33; myarray[1] = 71; myarray[2] = -16; myarray[3] = 45; // Display length System.out.println("myarray.length = " + myarray.length); // Display elements System.out.println(myarray[0]); System.out.println(myarray[1]); System.out.println(myarray[2]); System.out.println(myarray[3]); } }
__________________
I am a Java n00b.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-21-2008, 03:14 PM
Moderator
 
Join Date: Nov 2007
Posts: 1,657
Java Tip will become famous soon enoughJava Tip will become famous soon enough
It is easy. Check array initialization part of Java tutorial again and use one println statement inside a for loop where array index is replaced with loop control variable!
__________________
Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums! (closes on July 27, 2008)
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 04-21-2008, 07:31 PM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 841
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
Quote:
Originally Posted by Java Tip View Post
It is easy. Check array initialization part of Java tutorial again and use one println statement inside a for loop where array index is replaced with loop control variable!
Well said!

Zebra, should this solve your answer, please mark this thread as solved- if not, post back your updated code and we'll assist you.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums!
(closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
!
Got a little Capt'n in you? (drink responsibly)
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 04-22-2008, 08:27 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,574
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Yep, don't have any feedback from Zebra on what JavaTip and Captain says. It's not a difficult one. JavaTip gives all the details there.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 04-23-2008, 02:52 PM
Zebra's Avatar
Member
 
Join Date: Apr 2008
Location: Louisville, Indiana/Kentucky
Posts: 64
Zebra is on a distinguished road
So where do I put the for-loop. Sorry?
__________________
I am a Java n00b.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 04-23-2008, 03:11 PM
sanjeevtarar's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Delhi(India)
Posts: 249
sanjeevtarar is on a distinguished road
hello zebra,

As you have told that you are fresher, then my advise is to read some core java fundamentals books and do some research on programs . If you do something at your own then you will learn more. and one more thing do more and more practice on core java. CORE JAVA IS THE TOUGHEST part in Java language, Once you grab good knowledge on core part you will not get difficulty on other parts like servlets,jsp etc.

well for now i think you require this.

Code:
class OneDimensionArray { public static void main(String args[]) { // Declare and allocate space int myarray[] = new int[]{33,71,-16,45}; // Initialize elements // Display length System.out.println("myarray.length = " + myarray.length); // Display elements for (int i=0;i<myarray.length;i++ ){ System.out.println(myarray[i]); } } }
__________________
sanjeev,संजीव
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 04-23-2008, 03:15 PM
Zebra's Avatar
Member
 
Join Date: Apr 2008
Location: Louisville, Indiana/Kentucky
Posts: 64
Zebra is on a distinguished road
Thank you very much! I am in a java programming I class and he tries to just teach us, without books and stuff. But, thanks again. I will research.
__________________
I am a Java n00b.
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 04-24-2008, 05:03 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,574
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
You got the answer It's not difficult pal. Read more about and do some experiment yourself.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Noob question- easy mattonitto New To Java 7 06-13-2008 01:26 AM
Some problems with arrays and loops BHCluster New To Java 3 04-16-2008 01:24 PM
help me with a realy easy program (substring) michcio New To Java 7 01-27-2008 01:41 AM
Easy question JavaNoob New To Java 10 08-03-2007 11:28 PM
easy way to study the java springs concept kumar84 New To Java 1 07-17-2007 04:53 PM


All times are GMT +3. The time now is 08:22 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org