QUESTION 13:
Write two separate programs to generate the following patterns using iteration/loop
statements
in java
Attachments:
Answers
Answered by
1
Pattern 1:
public class pattern1 {
public static void main(String[] args) {
for(int i =1; i<=5; i++){
for(int j = 1; j<=i; j++){
if(j%2 == 0){
System.out.print("# ");
}
else{
System.out.print("* ");
}
}
System.out.println();
}
}
}
Pattern 2:
public class pattern2 {
public static void main(String[] args) {
for(int i =1; i<=5; i++){
for(int j = 5; j>=i; j--){
System.out.print(j+" ");
}
System.out.println();
}
}
}
Similar questions