Question

JAVA How could you print a rectangle with a specific number of rows and columns, and...

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.

Homework Answers

Answer #1

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:-

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
JAVA How would you use for loops to print a triangle inside of a rectangle given...
JAVA How would you use for loops to print a triangle inside of a rectangle given the user inputs a specific number of rows and columns for the rectangle? And edit the first and last lines. Not using an array Ex: Rows = 10, Columns = 15 *############## **$$$$$$$$$$$$$ ***$$$$$$$$$$$$ ****$$$$$$$$$$$ *****$$$$$$$$$$ ******$$$$$$$$$ *******$$$$$$$$ ********$$$$$$$ *********$$$$$$ **********$$$$$ **********$$$$$ *********$$$$$$ ********$$$$$$$ *******$$$$$$$$ ******$$$$$$$$$ *****$$$$$$$$$$ ****$$$$$$$$$$$ ***$$$$$$$$$$$$ **$$$$$$$$$$$$$ *##############
Summary In this lab, you add nested loops to a Java program provided. The program should...
Summary In this lab, you add nested loops to a Java program provided. The program should print the letter E. The letter E is printed using asterisks, three across and five down. Note that this program uses System.out.print("*"); to print an asterisk without a new line. Instructions Write the nested loops to control the number of rows and the number of columns that make up the letter E. In the loop body, use a nested if statement to decide when...
JAVA PROGRAMMING: Write a program called TimeSymbolTables that creates three symbol tables, each of a different...
JAVA PROGRAMMING: Write a program called TimeSymbolTables that creates three symbol tables, each of a different implementation. Each symbol table will contain as a key a word read from a text file and as a value the number of times that word occurs in the text file. Have the program fill the first symbol table with these counts, keeping track of how long that takes using a Stopwatch object. It then does the same thing with the second symbol table....
C++ Create a program that will use pointers to determine the average (to 1 decimal place)...
C++ Create a program that will use pointers to determine the average (to 1 decimal place) of a series of grades entered into an array. You can assume a maximum of 15 students and the user will end input with a sentinel value. Make sure to use pointer increment and a pointer comparison while loop, and not array notation or array index numbers or offsets. You will use a function called getgrades. Send the array name (a pointer constant) to...
IN JAVA!! You may be working with a programming language that has arrays, but not nodes....
IN JAVA!! You may be working with a programming language that has arrays, but not nodes. In this case you will need to save your BST in a two dimensional array. In this lab you will write a program to create a BST modelled as a two-dimensional array. The output from your program will be a two-dimensional array.   THEN: practice creating another array-based BST using integers of your choice. Once you have figured out your algorithm you will be able...
8.36 Lab 8a: Count by 3 Introduction For this lab, you will use a while loop...
8.36 Lab 8a: Count by 3 Introduction For this lab, you will use a while loop to complete the task. A while loop has this basic structure: /* variable initializations */ while (/*stop condition*/){ /* statements to be performed multiple times */ /* make sure the variable that the stop condition relies on is changed inside the loop. */ } Despite the structure of the while loop being different than that of a for loop, the concept behind it is...
Create in JAVA Suppose you are designing a game called King of the Stacks. The rules...
Create in JAVA Suppose you are designing a game called King of the Stacks. The rules of the game are as follows:  The game is played with two (2) players.  There are three (3) different Stacks in the game.  Each turn, a player pushes a disk on top of exactly one of the three Stacks. Players alternate turns throughout the game. Each disk will include some marker to denote to whom it belongs.  At the end...
Leave comments on code describing what does what Objectives: 1. To introduce pointer variables and their...
Leave comments on code describing what does what Objectives: 1. To introduce pointer variables and their relationship with arrays 2. To introduce the dereferencing operator 3. To introduce the concept of dynamic memory allocation A distinction must always be made between a memory location’s address and the data stored at that location. In this lab, we will look at addresses of variables and at special variables, called pointers, which hold these addresses. The address of a variable is given by...
6.12 LAB: Grade distribution In this lab, you will write a JavaScript program that generates a...
6.12 LAB: Grade distribution In this lab, you will write a JavaScript program that generates a bar graph of letter grades from a distributions of scores. Implement the parseScores function (1 point) Implement the parseScores function to take a space-separated string of scores as an argument and return an array of score strings. Each score is a number in the range [0, 100]. Ex: "45 78 98 83 86 99 90 59" → ["45","78","98","83","86","99","59"] Hint: JavaScript's string split() function can...
Use Python 3.8: Problem Description Many recipes tend to be rather small, producing the fewest number...
Use Python 3.8: Problem Description Many recipes tend to be rather small, producing the fewest number of servings that are really possible with the included ingredients. Sometimes one will want to be able to scale those recipes upwards for serving larger groups. This program's task is to determine how much of each ingredient in a recipe will be required for a target party size. The first inputs to the program will be the recipe itself. Here is an example recipe...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT