Write a program to accept a character and the number of rows display that character in a
given number of rows
Character is @
Rows is 4
Sample output -
@@@@
@@@@
@@@@
@@@@
atrs7391:
programming language?
Answers
Answered by
0
Answer:
If you find any problems related to the program, feel free to comment me down, if it's alright please let me know too..
Attachments:
Answered by
1
Required Answer:-
Question:
- Write a program to accept a character and number of rows and display the character in a given number of rows.
Solution:
Here is your program. It is written in Java.
import java.util.*;
public class Pattern {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("Enter a character: ");
char ch=sc.next().charAt(0);
System.out.print("Enter the number of rows: ");
int n=sc.nextInt();
for(int i=1;i<=n;i++) {
for(int j=1;j<=n;j++)
System.out.print(ch+" ");
System.out.println();
}
sc.close();
}
}
Explanation:
- Ask the user to enter the character and number of rows. Now, create two nested loop that iterates n times. Inside the inner loop, print the character.
Output is attached.
Attachments:
Similar questions