-
For loop with String as the var type
below is the code. the highlighted is the problem. the output for the code below is
Country:
[Malaysia, Indonesia, Korea, Germany, London]
[Malaysia, Indonesia, Korea, Germany, London]
[Malaysia, Indonesia, Korea, Germany, London]
[Malaysia, Indonesia, Korea, Germany, London]
[Malaysia, Indonesia, Korea, Germany, London]
Original contents of vals2: 11 22 33 44 55
Sum of values: 165
i want to make it
Country: Original Contents of Vals2
Malaysia 11
Indonesia 22
Korea 33
Germany 44
London 55
Sum of values: 165
can anyone help me how can i accomplish this? thanks
Code:
package com;
import java.util.ArrayList;
public class Test2 {
/**
* @param args
*/
public static void main(String args[]) {
ArrayList<String> vals = new ArrayList<String>();
ArrayList<Integer> vals2 = new ArrayList<Integer>();
vals.add("Malaysia");
vals.add("Indonesia");
vals.add("Korea");
vals.add("Germany");
vals.add("London");
vals2.add(11);
vals2.add(22);
vals2.add(33);
vals2.add(44);
vals2.add(55);
System.out.println("Country: ");
for (String v : vals)
System.out.println(vals + " ");
System.out.print("Original contents of vals2: ");
for (int v2 : vals2)
System.out.print(v2 + " ");
System.out.println();
//String sum = 0;
int sum2 = 0;
//for (String v : vals)
// count += v;
for (int v2 : vals2)
sum2 += v2;
//System.out.println("Sum of values: " + vals);
System.out.println("Sum of values: " + sum2);
}
}
Similar Threads
-
By Fred Mayes in forum Java
Replies: 1
Last Post: 06-05-2001, 06:12 AM
-
By Julian Milano in forum VB Classic
Replies: 2
Last Post: 08-11-2000, 12:11 PM
-
By Julian Milano in forum VB Classic
Replies: 0
Last Post: 08-10-2000, 09:16 PM
-
By Chandra in forum VB Classic
Replies: 0
Last Post: 06-22-2000, 12:52 PM
-
By Chandra in forum VB Classic
Replies: 0
Last Post: 06-22-2000, 07:30 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks