-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnhancedForLoopWithString.java
More file actions
31 lines (24 loc) · 969 Bytes
/
EnhancedForLoopWithString.java
File metadata and controls
31 lines (24 loc) · 969 Bytes
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
package enhancedforloopwithstring;
public class EnhancedForLoopWithString {
public static void main(String[] args) {
String shakil[]={"Shakil","Pakil","Shaki","Shakilla","Pakilla"};
//enhenced for lop starts here
//strng is the variable where we store the arrays values and shakil is the array name
for(String stng:shakil){
if(stng.startsWith("sha")){
System.out.println(stng+" starts with sha"+"\n");
}
else if(stng.startsWith("Pak")){
System.out.println(stng+" starts with pak"+"\n");
}
}
for(String stng:shakil){
if(stng.endsWith("killa")){
System.out.println(stng+" ends with killa"+"\n");
}
else if(stng.startsWith("kil")){
System.out.println(stng+" ends with kil"+"\n");
}
}
}
}