Advertisement
rafibatam

Nested Loop

Jan 4th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.49 KB | None | 0 0
  1. class NestedLoop {
  2.     public static void main(String[] args) {
  3.         for(int y = 1; y <= 9; y++) {
  4.            
  5.             for(int x = 1; x <= 9; x++) {
  6.                
  7.                 if(x == y) {
  8.                     System.out.print("* ");
  9.                 }
  10.                
  11.                 else if(x == 10 - y) {
  12.                     System.out.print("* ");
  13.                 }
  14.                
  15.                 else if(x == 5) {
  16.                     System.out.print("* ");
  17.                 }
  18.                
  19.                 else if(y == 5) {
  20.                     System.out.print("* ");
  21.                 }
  22.                
  23.                 else {
  24.                     System.out.print("  ");
  25.                 }
  26.             }
  27.            
  28.             System.out.println();
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement