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 08-06-2007, 04:42 AM
Member
 
Join Date: Jul 2007
Posts: 39
coco is on a distinguished road
Help with array in java
Hi, I am trying to code the following information, however I am getting some error when I try to add array 5, than add array 6 and add both array 5 and 6 together to get the total sum

Using separate arrays, code the following information:

Code:
Array #1] 34232, John Doe, 3xcvbn Array #2] 90323, Bill Reb, 2129uio Array #3] 10021, Eric Quick, 3898qas Array #4] 91920, Bob Bark, hjd2314 Array #5] 3, 2, 4, 5, 6 Array #6] 9, 7, 12, 15, 17 Display on the screen the following output: Secret Route----Name-----Code 3xcvbn........John Doe......34232 2129uio......Bill Reb.........90323 3898qas.....Eric Quick.....10021 hjd2314......Bob Bark......91920 Output the SUM of array5 (The value that is returned should be obtained by adding up all the numbers in the array) Output the SUM of array6 (The value that is returned should be obtained by adding up all the numbers in the array) Output the SUM of array5 + array6
Sortfriends.java
Code:
public class Sortfriends { public static void main (String[] args) { Contact[]friends = new Contact[5]; friends [0] = new Contact ("Secret Route", "Name", "code"); friends [1] = new Contact ("3xcvbn", "John Doe", "34232"); friends [2] = new Contact ("2129uio", "Bill Rep", "90323"); friends [3] = new Contact ("3898qas", "Eric Quick", "10021"); friends [4] = new Contact ("hjd234", "Bob Bark", "91920"); int[] numbercode = (3, 2, 4, 5, 6); int[] numbercode2 = (9, 7, 12, 15, 17); for (int index=0; index < 5; ++index) System.out.println (friends[index]); int sum1 = 0; int sum2 = 0; for (int i = 0; i < numbercode.length; i++) sum1 += numbercode[i]; System.out.println (sum1); for (int i = 0; i < numbercode2.length; i++) sum2 += numbercode2[i]; System.out.println (sum2); System.out.println (sum1 + sum2); } }
Thanks.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-06-2007, 05:03 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,144
hardwired is on a distinguished road
Code:
C:\jexp>javac v.java v.java:6: ')' expected int[] numbercode = (3, 2, 4, 5, 6); ^ v.java:7: ')' expected int[] numbercode2 = (9, 7, 12, 15, 17); ^
Use curley braces for array instantiation, not parentheses:
Code:
int[] numbercode = { 3, 2, 4, 5, 6 }; int[] numbercode2 = { 9, 7, 12, 15, 17 };
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
Java Array of Structure PAffiliates New To Java 1 01-28-2008 07:08 AM
how to pass array in java? sivasayanth New To Java 3 01-13-2008 05:33 PM
how to convert a Java array to a java stack? pompeez New To Java 2 08-13-2007 03:41 PM
Help with string and array in java zoe New To Java 1 08-07-2007 07:12 AM
Help with array and files in java fernando New To Java 1 07-31-2007 08:52 PM


All times are GMT +3. The time now is 10:03 PM.


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