Nested Loop - Lab excercise


// your name here

/**************
    LAB EXERCISE:
 
 First run this code, then modify if to make the output look likes this:

....1
...2.
..3..
.4...
5....

******************/

public class NestedLoop_Firstname_Lastname
{

public static void main(String[] args)
{
for (int line = 1; line <= 5; line++) {
   for (int j = 1; j <= (5 - line); j++) {
       System.out.print(".");
   }
   for (int k = 1; k <= line; k++) {
       System.out.print(line);
   }
   System.out.println();
}

}

}

No comments:

Post a Comment