-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtendedLoops.java
More file actions
63 lines (52 loc) · 1.6 KB
/
Copy pathExtendedLoops.java
File metadata and controls
63 lines (52 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package com.creatio.crm.language.basics;
import java.util.HashMap;
import java.util.Map;
public class ExtendedLoops {
public static void main(String[] args) {
//Extended for loop
/*
* Create a HashMap with 5 countries and their capitals: India → New Delhi Japan
* → Tokyo USA → Washington France → Paris Brazil → Brasilia
*
* Then using for-each loops:
*
* Print all keys (countries) Print all values (capitals) Print both together
* like India : New Delhi Find and print the country whose capital contains
* letter "o"
*/
Map<String, String> country = new HashMap<String, String>();
country.put("India", "New Delhi");
country.put("Japan", "Tokyo");
country.put("USA", "Washinton");
country.put("Brazil", "Brasilia");
country.put("France", "Paris");
System.out.println("Countries:");
for (String key : country.keySet()) {
System.out.println(key);
}
System.out.println("The countries' capital: ");
for (String key : country.keySet()) {
System.out.println(country.get(key));
}
System.out.println("Countries along with it's capitals: ");
for (String key : country.keySet()) {
System.out.println(key + ":" + country.get(key));
}
System.out.println("Countries along with it's capitals containing 'o': ");
for (String key : country.keySet()) {
if (country.get(key).contains("o")) {
System.out.println(key + ":" + country.get(key));
}
}
//do while loop
//first execute then checks conditions
int i=0;
do {
if(i>=10) {
break;
}
System.out.println("!!!!!!!Refresh the page!!!!!!!!"+i);
i++;
}while(i>0);
}
}