Write a Java program using a single multi-level nested for-loop to display the following pattern (For each iteration, only one character can be printed) :
1,2,3,4,5,6,7,8,9#1,2,3,4,5,6,7,8,9#1,2,3,4,5,6,7,8,9# 3,6,9,12,15,18,21,24,27#3,6,9,12,15,18,21,24,27#3,6,9,12,15,18,21,24,27# 5,10,15,20,25,30,35,40,45#5,10,15,20,25,30,35,40,45#5,10,15,20,25,30,35,40,45#
// TestCode.java public class TestCode { public static void main(String args[]) { for(int i = 1;i<=5;i+=2){ int n = i; for(int j = 1;j<27;j++){ if(j%9==0){ System.out.print(n+"#"); n = 0; } else{ System.out.print(n+","); } n += i; } System.out.println(9*i+"#"); } } }
Get Answers For Free
Most questions answered within 1 hours.