0% found this document useful (0 votes)
2 views

DigitPattern

The document contains a Java program named DigitPattern that prompts the user to input two numbers between 1 and 9. It then prints a pattern of the first number in rows determined by the second number, decreasing the number of printed digits with each row. The program includes input validation to ensure the numbers are within the specified range.

Uploaded by

tmemabo5
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

DigitPattern

The document contains a Java program named DigitPattern that prompts the user to input two numbers between 1 and 9. It then prints a pattern of the first number in rows determined by the second number, decreasing the number of printed digits with each row. The program includes input validation to ensure the numbers are within the specified range.

Uploaded by

tmemabo5
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

DigitPattern.

java Tuesday, 4 April 2023, 21:45

1 import java.util.Scanner;
2
3 public class DigitPattern {
4 public static void main(String[] args) {
5 Scanner input = new Scanner(System.in);
6
7 int num1, num2;
8
9 do {
10 System.out.println("Enter the first number (1-9): ");
11 num1 = input.nextInt();
12 } while (num1 < 1 || num1 > 9);
13
14 do {
15 System.out.println("Enter the second numebr(rows) (1-9): ");
16 num2 = input.nextInt();
17 } while (num2 < 1 || num2 > 9);
18
19 int numRows = num2;
20 for (int i = 1; i <= numRows; i++) {
21 printDigits(num1, num2);
22 System.out.println();
23 num2--;
24 }
25 }
26
27 private static void printDigits(int num1, int num2) {
28 for (int j = num2; j >= 1; j--) {
29 System.out.print(num1);
30 }
31 }
32 }
33

Page 1

You might also like