JAVA:
How could you print a rectangle with a specific number of rows and columns, and split it into sections that each print a different inputted symbol?
For example, if rows = 16, columns = 10, and the sections = 4 where the three symbols = #, $, and % the following would print:
##########
##########
##########
##########
$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$$$
**********
**********
**********
**********
##########
##########
##########
##########
Where the pattern repeats until the number of sections is met.
//TestCode.java public class TestCode { public static void main(String[] args) { char arr[] = {'#','$','%'}; int rows = 16, columns = 10, sections = 4; for(int i = 0;i<rows;i++){ for(int j = 0;j<columns;j++){ if(i/sections==0 || i/sections==3){ System.out.print(arr[0]); } else if(i/sections==1){ System.out.print(arr[1]); } else{ System.out.print(arr[2]); } } System.out.println(); } } }
Get Answers For Free
Most questions answered within 1 hours.