Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Write a program that reads from the console a positive integer number n (1 ≤ n ≤ 20)
- * and prints a matrix. Use two nested loops. */
- import java.util.Scanner;
- public class _09_MatrixOfNumbers {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Scanner scan = new Scanner(System.in);
- System.out.print("Enter a whole number in the range [1 .. 20] for N: ");
- int numN = scan.nextInt();
- scan.close();
- if (numN > 0 && numN <= 20) {
- System.out.println("The Matrix of Numbers is:");
- for (int row = 1; row <= numN; row++) {
- for (int col = row; col < row + numN; col++) {
- System.out.printf("%3d", col);
- }
- System.out.println();
- }
- } else {
- System.out.println("Error! - Invalid Input number!!!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement