Write a Java program to display a specified pattern- Within your program you mus
ID: 3864243 • Letter: W
Question
Write a Java program to display a specified pattern- Within your program you must define a recursive method with the following signature public static void Pattern1(int m: int n). Your program will ask the user to input two integers, the first one is for the number of the row in the pattern and the second one, which is between 0 and 9 inclusively, is for the entries in the pattern, and your program invokes the method. A sample run of your program is as follows. Please input the first integer. 3 Please input the second integer 0 The pattern is as follows. 0 00 000 Another sample run of your program is as follows Please input the first integer 5 Please input the second integer 9 The pattern is as follows. 9 99 999 9999 99999Explanation / Answer
code.java:
import java.util.Scanner;
public class code {
public static void Patern1(int m, int n)
{
if (m == 0)
{
System.out.print(n);
}
else
{
for(int i = 1; i<= m; i++)
{
for(int j = 1; j<= i; j++)
{
Patern1(0,n);
}
System.out.print(" ");
}
}
}
public static void main(String[] args)
{
int n,m;
Scanner scanner = new Scanner(System.in);
System.out.println("Enter first integer: ");
n = scanner.nextInt();
System.out.println("Enter second integer: ");
m = scanner.nextInt();
Patern1(n,m);
}
}
Sample Output:
Enter first integer:
5
Enter second integer:
9
9
99
999
9999
99999
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.