View Single Post
  #1 (permalink)  
Old 08-06-2007, 05:42 AM
coco coco is offline
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.
Reply With Quote
Sponsored Links