Question

In: Computer Science

Given two integers N1 and N2, display the given box number pattern of '1's with a...

Given two integers N1 and N2, display the given box number pattern of '1's with a '0' at the center (Square number patterns).

Input:
5

5

    where:

  • First line represents the value of N1( number of rows ).
  • Second line represents the value of N2( number of columns ).

Solutions

Expert Solution

import java.util.Scanner;
public class BoxPattern {
        public static void main(String[] args) {
                Scanner sc = new Scanner(System.in);
                int m = sc.nextInt(); //get number of rows
                int n = sc.nextInt(); //get number of columns
                printPattern(m, n); //call method printPattern()
                
        }
        public static void printPattern(int m, int n)
        {
                for(int i = 0; i<m; i++) //loop throwugh rows
                {
                        for(int j = 0; j<n; j++) //loop through columns
                        {
                                if(i == 0 || i == m-1 || j == 0 || j == n-1) //if it is the first/last row/column
                                {
                                        System.out.print(1+" "); //print 1
                                }
                                else
                                {
                                        System.out.print(0 + " "); //print 0 
                                }
                        }
                        System.out.println(); //change line
                }
        }
}

Output below:

4
4
1 1 1 1 
1 0 0 1 
1 0 0 1 
1 1 1 1 

Kindly upvote if this version is correct.


Related Solutions

Say that two users use n1, n2 in the RSA and gcd(n1, n2) =/= 1. How...
Say that two users use n1, n2 in the RSA and gcd(n1, n2) =/= 1. How can we break their system?
Write a program in java which randomly generates two integer number n1 and n2 (suppose the...
Write a program in java which randomly generates two integer number n1 and n2 (suppose the range for each integer is [1, 100]), then asks the user what is the value of n1*n2, if the user’s answer is correct, call method printGoodComment to print out something nice, otherwise, call printBadComment to print out something “mean”. The method signatures are:                   public static void printGoodComment() and                   public static void printBadComment() in your printGoodComment method, it will randomly print one sentence from the...
Write a program in java which randomly generates two integer number n1 and n2 (suppose the...
Write a program in java which randomly generates two integer number n1 and n2 (suppose the range for each integer is [1, 100]), then asks the user what is the value of n1*n2, if the user’s answer is correct, call method printGoodComment to print out something nice, otherwise, call printBadComment to print out something “mean”. The method signatures are:                   public static void printGoodComment() and                   public static void printBadComment() in your printGoodComment method, it will randomly print one sentence from the...
1. Given with the following sample information n1 = 125, n2 = 120; s1 = 31,...
1. Given with the following sample information n1 = 125, n2 = 120; s1 = 31, s2 = 38; x1-bar = 116, x2-bar = 105 Test the following hypotheses, assuming a significance level of 0.05 is to be used with equal variances. Ho : µ1 - µ2 = 0 HA : µ1 - µ2 ≠ 0 What is your conclusion? a) Since t test statistic = 1.82 < t-critical value = 2.49, we do not reject Ho. b) Since t...
Single inheritance Given two integer numbers N1 and N2, create a class 'ProblemSolution' with following characteristics....
Single inheritance Given two integer numbers N1 and N2, create a class 'ProblemSolution' with following characteristics. Must extend a 'Base' class. Create a method 'solution' with two integer parameters (N1 and N2) and long return type. The 'solution' method should call the addition and subtraction methods of 'Base' class and return multiplication of returned results of addition and subtraction method. Result = (N1 + N2) * (N1 - N2) What is inheritance? Inheritance is a mechanism in which one object...
Given two independent random samples with the following results: n1   463   n2   295 p1   0.77   p2  ...
Given two independent random samples with the following results: n1   463   n2   295 p1   0.77   p2   0.89 Use this data to find the 99%99% confidence interval for the true difference between the population proportions. Step 1 of 3: Find the critical value that should be used in constructing the confidence interval. Step 2 of 3: Find the value of the standard error. Round your answer to three decimal places. Step 3 of 3: Construct the 99% confidence interval. Round your...
Write a program that asks the user to enter a number. Display the following pattern by...
Write a program that asks the user to enter a number. Display the following pattern by writing lines of asterisks. The first line will have one asterisk, the next two, and so on, with each line having one more asterisk than the previous line, up to the number entered by the user.For example, if the user enters 5, the output would be: * *   * *   *   * *   *   *   * *   *   *   *   * short codes please
If I roll the six-sided dice 4times, Let N1 be the number of 2 and N2...
If I roll the six-sided dice 4times, Let N1 be the number of 2 and N2 be the number of 6 so what is the probability mass function of N1 and N2? and what is the covariance between two random variables
(S 11.1) Random samples of sizes n1 = 404 and n2 = 310 were taken from...
(S 11.1) Random samples of sizes n1 = 404 and n2 = 310 were taken from two independent populations. In the first sample, 107 of the individuals met a certain criteria whereas in the second sample, 135 of the individuals met the same criteria. Run a 2PropZtest to test whether the proportions are different, and answer the following questions. What is the value of p?, the pooled sample proportion?Round your response to at least 3 decimal places. Calculate the z...
Given two independent random samples with the following results: n1=350 n2=475 p1=0.55 p2=0.68 Can it be...
Given two independent random samples with the following results: n1=350 n2=475 p1=0.55 p2=0.68 Can it be concluded that the proportion found in Population 2 exceeds the proportion found in Population 1? Use a significance level of α=0.05 for the test. Step 1 of 5 : State the null and alternative hypotheses for the test. State the null and alternative hypotheses for the test Find the values of the two sample proportions, pˆ1 and pˆ2. Round to 3 decimal places Compute...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT