Knowee
Questions
Features
Study Tools

Develop an algorithm and write a Java that must accept two integers N1 and N2 as the input. The program must print the desired pattern as shown in the Sample test cases.Input FormatThe first line contains the two integers N1 and N2 as the input.Output FormatPrint the desired pattern as shown in the Sample test cases.Boundary Condition: 0  <  N1, N2  <= 1000Otherwise, print ‘invalid’

Question

Develop an algorithm and write a Java that must accept two integers N1 and N2 as the input. The program must print the desired pattern as shown in the Sample test cases.Input FormatThe first line contains the two integers N1 and N2 as the input.Output FormatPrint the desired pattern as shown in the Sample test cases.Boundary Condition: 0  <  N1, N2  <= 1000Otherwise, print ‘invalid’

🧐 Not the exact question you are looking for?Go ask a question

Solution 1

Here is a simple Java program that accepts two integers N1 and N2 as input and prints a pattern. This program also checks the boundary conditions and prints 'invalid' if the input is not within the specified range.

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N1 = scanner.nextInt();
        int N2 = scanner.nextInt();

        if (N1 <= 0 || N1 > 1000 || N2 <= 0 || N2 > 1000) {
            System.out.println("invalid");
            return;
        }

        for (int i = 0; i < N1; i++) {
            for (int j = 0; j < N2; j++) {
                System.out.print("* ");
            }
            System.out.println();
        }
    }
}

This program first reads the two integers N1 and N2. It then checks if these numbers are within the specified range. If not, it prints 'invalid' and ends the program. If the numbers are within the range, it prints a pattern of asterisks, with N1 rows and N2 columns.

Please note that the pattern to be printed is not specified in your question. The above program prints a rectangle of asterisks. If you need a different pattern, you will need to modify the nested for loops accordingly.

This problem has been solved

Solution 2

Here is a simple Java program that accepts two integers N1 and N2 as input and prints a pattern. This program also checks the boundary conditions and prints 'invalid' if the input is not within the specified range.

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N1 = scanner.nextInt();
        int N2 = scanner.nextInt();

        if (N1 <= 0 || N1 > 1000 || N2 <= 0 || N2 > 1000) {
            System.out.println("invalid");
            return;
        }

        for (int i = 0; i < N1; i++) {
            for (int j = 0; j < N2; j++) {
                System.out.print("* ");
            }
            System.out.println();
        }
    }
}

This program first reads the two integers N1 and N2. It then checks if these numbers are within the specified range. If not, it prints 'invalid' and ends the program. If the numbers are within the range, it prints a pattern of asterisks. The number of rows in the pattern is equal to N1 and the number of asterisks in each row is equal to N2.

Please note that the pattern to be printed is not specified in the question. I have assumed that the pattern is a rectangle of asterisks. If the pattern is different, you will need to modify the nested for loop accordingly.

This problem has been solved

Solution 3

The problem statement is not clear. It does not provide information about the pattern that needs to be printed. Could you please provide more details or examples of the pattern?

Similar Questions

Design an algoritm and write a Java program with a class that read an integer ‘n’ as input and print the ‘n’ natural numbers in descending order sequence and their “Sum”. Print ‘invalid’ if the boundary conditions are not met.Boundary Condition: 0 < n > 1000Input Format:The first line contains an integer ‘n’Output Format:The first ‘n’ line contains the natural numbers in descending sequence or invalidThe ‘n+1’th line contains the Sum

Sam is organizing a coding workshop and wants to include a fun exercise involving patterns. The task is to create a program that takes an integer n as input and generates a specific pattern. The pattern is given below.Input: 5Output:Input format :The input consists of an integer n.Output format :The output prints the specified pattern.Code constraints :2 ≤ n ≤ 50Sample test cases :Input 1 :5Output 1 : ** ****** ************* ******* ***** *** *Input 2 :6Output 2 : *** ******** **************** ********* ******* ***** *** *

An integer value N is passed as the input. The program must print YES if N is prime number. Else the program must print NO.Input Format:The first line denotes the value of N.Output Format:YES or NO based on if N is a prime number or not. (The OUTPUT is CASE SENSITIVE).Boundary Conditions:2 <= N <= 9999999Example Input/Output 1:Input:19Output:YESExample Input/Output 2:Input:189210Output:NO

Create a Java program that takes two integer inputs 'a' and 'b' from the user and calculates 'a/b'. Implement exception handling to catch potential arithmetic and input mismatch errors, providing appropriate error messages for each case.Your task is to write a Java Program to Handle Arithmetic Exceptions and InputMisMatchExceptions.Note: Refer to the visible test cases for more clarity.Constraint:0≤𝑎≤1020≤𝑏≤102Input Format: The input consists of two numbers each in a new line (integer).Output Format: The output represents the result of the division of the two numbers or any error that occurred while dividing.Sample Test CasesTest Case 1:Expected Output:Enter·the·value·of·'a':·1Enter·the·value·of·'b':·0Arithmetic·Exception:·/·by·zeroTest Case 2:Expected Output:Enter·the·value·of·'a':·sInput·Mismatch·Exception:·Please·enter·valid·integer·values.Test Case 3:Expected Output:Enter·the·value·of·'a':·50Enter·the·value·of·'b':·4Result·of·a/b:·12

Given an integer ‘n’, Develop an algorithm and write a java program to check whether it is a Narcissistic number or not.Note: Narcissistic Number is a number that is the sum of its own digits each raised to the power of the number of digits.Boundary Condition: 0  <  n  <= 10000Otherwise, print ‘invalid’ Input FormatNumber ‘n’Output Formatprint a single line containing the string "yes" if the presented scenario is possible or "no" otherwise (without quotes).

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.