Question

Write a Java application that displays the following output pattern: Thus, there are+signs everywhere except the diagonal, which has. signs. There are no blank characters. Requirements and Restrictions: The number of lines and the number of characters per line, i.e. the size of the square pattern and line argument. For example, the size of the above square is 11 and it is specified through the following compile and execute commands: e >javac PrintPattern.java > java PrintPattern 11 Your program should work for any user specified positive integer value (11 is only one such example). . .Each plus symbols (+) should be printed by a single statement of the form: System.out.print+ . Each minus characters should be printed by a single statement of the form: System.out.print ) A statement of the form System.out.println( ); can be used to move to the next line. There should be no other output statements in the program. . .

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

Note: This is the program which will get the user input as command line argument.If u dont knowhow to run this program you may get error.

_______________

PrintPattern.java

public class PrintPattern {

public static void main(String[] args) {

//Getting the input from the user as command line argument
int n = Integer.parseInt(args[0]);

//Displaying the pattern
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (i == j)
System.out.print("-");
else
System.out.print("+");
}
System.out.println();
}

}

}

_______________

Output:

DNjavac PrintPattern.java D:Njava PrintPattern 11

________________Thank You

Add a comment
Know the answer?
Add Answer to:
Write a Java application that displays the following output pattern: Thus, there are+signs everywhere except the...
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
  • in Java This program will output a right triangle based on user specified height triangleHeight and...

    in Java This program will output a right triangle based on user specified height triangleHeight and symbol triangleChar. (1) The given program outputs a fixed-height triangle using a character. Modify the given program to output a right triangle that instead uses the user-specified trianglechar character. (1 pt) (2) Modify the program to use a nested loop to output a right triangle of height triangleHeight. The first line will have one user-specified character, such as % or* Each subsequent line will...

  • u are to write a program in Java that takes two sets of up to 5...

    u are to write a program in Java that takes two sets of up to 5 symbols(letters, numbers or any characters) and prints the cartesian product of the two sets. The program should allow the user to enter the characters for each set and the output should, consist of the name of each set followed by the characters and on the following line print the cartesian product. Example: {1,3,*} X {3,?,D} = {(1,3),(1,?),(1,D),(3,3),(3,?),(3,D,(*,3),(*,?),(*,D)} or {2,3,5,7} X (5,6} = {(2,5),(2,6),(3,5),(3,6),(5,5),(5,6),(7,5),(7,6)}

  • Hi. This is a prototype of Java. The following Java program was developed for prototyping a...

    Hi. This is a prototype of Java. The following Java program was developed for prototyping a mini calculator. Run the program and provide your feedback as the user/project sponsor. (Save the code as MiniCalculator.java; compile the file: javac MiniCalculator.java; and then run the program: java MiniCalculator). HINTs: May give feedback to the data type and operations handled by the program, the way the program to get numbers and operators, the way the calculation results are output, the termination of the...

  • (use the JOptionPane methods for input and output) Write a java application that prompts the user...

    (use the JOptionPane methods for input and output) Write a java application that prompts the user to input an integers x. Then the program should call the method isAutomorphic to check if the integer x is automorphic*or not. At the end the program should output a message to indicate if x is automorphic or not *In Mathematics, an automorphic number is a number that ends with the same digit that its square ends with. For Example: 762 = 5776    è  (76 is...

  • Coding Requirements for Assignment2_1.java: Based on Assignment1.java, re-do all 7 methods from triangle_0 to triangle_6 by...

    Coding Requirements for Assignment2_1.java: Based on Assignment1.java, re-do all 7 methods from triangle_0 to triangle_6 by storing characters (which could be symbols or digits) in a 2D "square" array, meaning it has equal number of rows and columns. Now, because each triangle is supposed to contain rows filled with different number of characters, you are required to fill each row with only required number of characters in this square array. For example, in an up-side-down 8-row triangle of "$", the...

  • IN JAVA Overview In this project you will implement a Java program that will print several...

    IN JAVA Overview 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 the user to decide between different forms...

  • I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that a...

    I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that accepts one integer parameter and returns the value raised to the third power as an integer. o Write a method called randominRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive. 2. o Write a method...

  • Java: Write a static method named longestName that reads a series of names typed by the...

    Java: Write a static method named longestName that reads a series of names typed by the user and prints the longest name (i.e., the name with the most characters). The method should accept a Scanner object, console and an integer, n as parameters. After prompting and reading in n names, the longest name should be printed as follows: its first letter should be capitalized and all subsequent letters lowercase, regardless of how the user entered the name. If there is...

  • Develop a Java application that provides program output in a logical manner and incorporates appropriate data...

    Develop a Java application that provides program output in a logical manner and incorporates appropriate data types. Similar to zyBooks examples in Chapter 2, your program should prompt a user to enter a car brand, model, year, starting odometer reading, ending odometer reading, and gallons used. The output should include this information along with the estimated miles per gallon consumed by the vehicle in the format MPG: your calculation. Print each on separate lines with the appropriate labels (example, MPG:...

  • 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...

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