Question

This solution must use methods. It is recommended to use methods for this solution. Write a program that reads an integer and……… Sample run 1 This program will display a full and an empty square given the side length. Enter the side length: 6 多多多多多多

In Jgrasp(Java) Thanks!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

ygnuBUSB口 System.out.print System.out.print(*); for(int i=0; i<n-2; i++) { if(row == 0 || row == n-1) { System.out.print(*

import java.util.Scanner;

public class PrintPattern {
    
    public static void printRow(int n, int row) {
        for(int i=0; i<n; i++) {
            System.out.print("*");
        }
        System.out.print(" ");
        System.out.print("*");
        for(int i=0; i<n-2; i++) {
            if(row == 0 || row == n-1) {
                System.out.print("*");
            } else {
                System.out.print(" ");
            }
        }
        System.out.println("*");
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        
        System.out.println("Enter value of n: ");
        int n = in.nextInt();
        
        for(int i=0; i<n; i++) {
            printRow(n, i);
        }
        System.out.println("Bye");
    }

}

**************************************************

Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.

Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.

Add a comment
Know the answer?
Add Answer to:
In Jgrasp(Java) Thanks! This solution must use methods. It is recommended to use methods for this...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • CIST 2371 Introduction to Java Unit 03 Lab Due Date: ________ Part 1 – Using methods...

    CIST 2371 Introduction to Java Unit 03 Lab Due Date: ________ Part 1 – Using methods Create a folder called Unit03 and put all your source files in this folder. Write a program named Unit03Prog1.java. This program will contain a main() method and a method called printChars() that has the following header: public static void printChars(char c1, char c2) The printChars() method will print out on the console all the characters between c1 and c2 inclusive. It will print 10...

  • You will turn in a java file named "MyMethods.java". It will contain one class named "MyMethods". That class will contain three methods. These methods must be in JOptionPane and must c...

    You will turn in a java file named "MyMethods.java". It will contain one class named "MyMethods". That class will contain three methods. These methods must be in JOptionPane and must contain: getAnInt will return a value of type int, and take as an argument a string to prompt the user. The actual prompt presented to the user should include not only the string argument, but also the information that the user may press Cancel or enter an empty string to...

  • PYTHON Fractal Drawing We will draw a recursively defined picture in this program. Create a function...

    PYTHON Fractal Drawing We will draw a recursively defined picture in this program. Create a function def fractal(length, spaces). This function will print out a certain number of stars * and spaces. If length is 1 print out the number of spaces given followed by 1 star. If the length is greater than one do the following: Print the fractal pattern with half the length and the same number of spaces. Print the number of spaces given followed by length...

  • You will implement and test several short recursive methods below. With the proper use of recursi...

    this can be done in one class or two separate classes,in java thanks! You will implement and test several short recursive methods below. With the proper use of recursion, none of these methods should require more than a dozen lines of code. Test all these in the same class. Keep adding methods and testing until all are working 5. A Fractal Pattern Examine this pattern of stars and blanks, and write a recursive method that can generate patterns such as...

  • Hello Guys. I need help with this its in java In this project you will implement...

    Hello Guys. I need help with this its in java In this project you will implement a Java program that will print several shapes and patterns according to uses input. This program will allow the use to select the type (say, rectangle, triangle, or diamond), the size and the fill character for a shape. All operations will be performed based on the user input which will respond to a dynamic menu that will be presented. Specifically, the menu will guide...

  • PLEASE USE VERY BASIC REGISTERS AND CODE TO DO THE FOLLOWING Objectives: -write assembly language programs...

    PLEASE USE VERY BASIC REGISTERS AND CODE TO DO THE FOLLOWING Objectives: -write assembly language programs to:             -define a recursive procedure/function and call it.             -use syscall operations to display integers and strings on the console window             -use syscall operations to read integers from the keyboard. Assignment Description: Implement a MIPS assembly language program that defines "main", and "function1" procedures. The function1 is recursive and should be defined as: function1(n) = (2*n)+9                      if n <= 5              =...

  • PLEASE READ THE FULL INSTRUCTION. Write a Java programme to print the pattern of asterisks shown...

    PLEASE READ THE FULL INSTRUCTION. Write a Java programme to print the pattern of asterisks shown below. For i=1 For i=2 * * For i=3 For i=n ** * ** ** ......... * (n asterisks) Your program should prompt the user to enter the value of n and then draw the corresponding star pattern. Remember if n is 5, you will have to print five patterns for i=1, i=2, i=3, i=4, and i=5. If n is 3, you will have...

  • Only use the code in Objectives and write the code in Python

    Only use the code in Objectives and write the code in Python Question 1. Study the examples below carefully and write a program for journal subscription Your program should work exactly as the following examples The text in bold indicates user input. Example 1: The user is a student, and the user subscribes to 2 journals Question 1 - Journal of Commodity Markets Journal of Sustainable Mining Journal of Asia-Pacific Biodiversity Student $21 $22 $27 Non-student $50 $60 $75 Are...

  • Use Java program Material Covered : Loops & Methods Question 1: Write a program to calculate...

    Use Java program Material Covered : Loops & Methods Question 1: Write a program to calculate rectangle area. Some requirements: 1. User Scanner to collect user input for length & width 2. The formula is area = length * width 3. You must implement methods getLength, getWidth, getArea and displayData ▪ getLength – This method should ask the user to enter the rectangle’s length and then return that value as a double ▪ getWidth – This method should ask the...

  • Java Program: In this project, you will write a program called GradeCalculator that will calculate the...

    Java Program: In this project, you will write a program called GradeCalculator that will calculate the grading statistics of a desired number of students. Your program should start out by prompting the user to enter the number of students in the classroom and the number of exam scores. Your program then prompts for each student’s name and the scores for each exam. The exam scores should be entered as a sequence of numbers separated by blank space. Your program will...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT