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 (without using an array)?
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.
The input varies each time so the program must account for different symbols/ values for rows, columns, and sections.
Source Code:
import java.util.*;
public class Main
{
public static void main(String[] args) {
int r,c,s,i,j;
Scanner sc=new
Scanner(System.in);
System.out.println("Enter
number of rows:"); //reading rows
r=sc.nextInt();
System.out.println("Enter
number of columns:"); //reading columns
c=sc.nextInt();
System.out.println("Enter
section size:"); //reading section size
s=sc.nextInt();
System.out.println("Enter the
symbols:"); //readin the symbols
sc.nextLine();
String str=sc.nextLine(); //
converting string of symbols into individual symbol
char
ch[]=str.toCharArray();
int k=0;
for (i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
System.out.print(ch[k]);
}
System.out.println();
if((i+1)%s==0)
{
k=k+1;
if(k==ch.length)
{
k=0;
}
}
}
}
}
Code Screenshot:
OUTPUT!:-
OUTPUT-2:-
Get Answers For Free
Most questions answered within 1 hours.