Advertisement
fosterbl

NestedForLoops.java

Jan 23rd, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.12 KB | None | 0 0
  1. public class NestedForLoops{
  2.    public static void main(String[] args){
  3.       //Example 1
  4.       for (int i = 1; i <= 3; i++) {
  5.          for (int j = 1; j <= 2; j++) {
  6.             System.out.println("six");
  7.          }
  8.       }
  9.      
  10.       //Example 2
  11. //       for (int i = 1; i <= 5; i++) {
  12. //          for (int j = 1; j <= 10; j++) {
  13. //             System.out.print(i + " " + j);
  14. //          }
  15. //          System.out.println(); // to end the line
  16. //       }
  17.      
  18.       //Example 3
  19. //       for (int i = 1; i <= 5; i++) {
  20. //          for (int j = 1; j <= 10; j++) {
  21. //             System.out.print( (i*j) + " ");
  22. //          }
  23. //          System.out.println(); // to end the line
  24. //       }
  25.      
  26.       //Example 4
  27. //       for (int i = 1; i <= 4; i++) {
  28. //          for (int j = 1; j <= 5; j++) {
  29. //             System.out.print("*");
  30. //          }
  31. //          System.out.println();
  32. //       }
  33.      
  34.       //Example 5
  35. //       for (int i = 1; i <= 6; i++) {
  36. //          for (int j = 1; j <= i; j++) {
  37. //             System.out.print("*");
  38. //          }
  39. //          System.out.println();
  40. //       }
  41.    }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement