Question

In: Computer Science

Java Programming Write a program that displays the following pattern *                         *       &nbsp

Java Programming

Write a program that displays the following pattern

*

                        *          *          *

*          *          *          *          *         

*          *          *          *          *          *          *

            *          *          *          *          *

                        *          *          *

                                    *

Printing Pattern A

*

**

***

****

*****

******

*******

Printing Pattern B

*******

******

*****

****

***

**

*

Printing Pattern C

*

**

***

****

*****

******

*******

Solutions

Expert Solution

public class Pattern {

  
public static void main(String[] args) {
int rows = 4;
int k = 0;
for(int i = 1; i <= rows; ++i, k = 0) {
for(int space = 1; space <= rows - i; ++space) {
System.out.print(" ");
}
while(k != 2 * i - 1) {
System.out.print("* ");
++k;
}
System.out.println();
}
for(int i = rows-1; i >= 1; --i) {
for(int space = 1; space <= rows - i; ++space) {
System.out.print(" ");
}
for(int j=i; j <= 2 * i - 1; ++j) {
System.out.print("* ");
}
for(int j = 0; j < i - 1; ++j) {
System.out.print("* ");
}
System.out.println();
}
System.out.println("Printing Pattern A");
int rowA = 7;
for (int i = 1; i <= rowA; i++) {
for (int j = 0; j < i ; j++) {
System.out.print("*");
  
}
System.out.println("");
  
}
System.out.println("Printing Pattern B");
int rowB = 7;
for (int i = rowB; i >= 1; i--) {
for (int j = 0; j < i ; j++) {
System.out.print("*");
  
}
System.out.println("");
  
}
System.out.println("Printing Pattern C");
int rowC = 7;
for (int i = 1; i <= rowC; i++) {
for (int j = 0; j < i ; j++) {
System.out.print("*");
  
}
System.out.println("");
  
}
}
}

/* OUTPUT */

/* PLEASE UPVOTE */


Related Solutions

java programming question: "Write a program that displays a page on a topic of interest to...
java programming question: "Write a program that displays a page on a topic of interest to you (e.g., a sport, a city). Include at least one image and one shape (which can be text). " I wanted to do a soccer page but I don't know how to put pictures from the internet on Java. As for my object, I wanted to make a soccer ball. My professor has been really confusing in explaining graphics so any help is appreciated!
CS 206 Visual Programming, Netbeans Problem: Write a Java program that displays all the leap years,...
CS 206 Visual Programming, Netbeans Problem: Write a Java program that displays all the leap years, 10 per line, from 1001 to 2100, separated by exactly one space. Also display the total number of leap years in this period. Hints: you need to use a loop ( for-loop is more suitable)
Write a Java program that reads a name and displays on the screen.
Write a Java program that reads a name and displays on the screen.
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user to enter the name of the month he/she was born in (example: September). b) Prompt the user to enter his/her weight in pounds (example: 145.75). c) Prompt the user to enter his/her height in feet (example: 6.5). d) Display (print) a line of message on the screen that reads as follows: You were born in the month of September and weigh 145.75 lbs. and...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user to enter a six-digit integer. b) Take the integer and break it up into two pieces of three-digits each (make sure you keep the order of digits). c) Display each 3-digit piece on a separate line with a proper message before each piece. For example, if the user enters  450835 as the integer, then the program should display the following output: Right 3-digit piece: 835...
URGENT!! DO THIS CODE IN JAVA Write a complete Java FX program that displays a text...
URGENT!! DO THIS CODE IN JAVA Write a complete Java FX program that displays a text label and a button.When the program begins, the label displays a 0. Then each time the button is clicked, the number increases its value by 1; that is each time the user clicks the button the label displays 1,2,3,4............and so on.
in java Write a Java Program that displays a menu with five different options: 1. Lab...
in java Write a Java Program that displays a menu with five different options: 1. Lab Test Average Calculator 2. Dice Roll 3. Circle Area Calculator 4. Compute Distance 5. Quit The program will display a menu with each of the options above, and then ask the user to enter their choice. There is also a fifth option to quit, in which case, the program will simply display a goodbye message. Based on the user’s choice, one of the options...
Write a JAVA program that displays a table of the Celsius temperatures and their Fahrenheit equivalents....
Write a JAVA program that displays a table of the Celsius temperatures and their Fahrenheit equivalents.  The formula for converting a temperature from Celsius to Fahrenheit is F = 9/ 5 C + 32 where F → Fahrenheit temperature C → Celsius temperature.  Allow the user to enter the range of temperatures in Celsius to be converted into Fahrenheit.  Your program must use a loop to display the values of the temperature conversions (see sample output). Sample...
in java Write a program that reads in ten numbers and displays the number of distinct...
in java Write a program that reads in ten numbers and displays the number of distinct numbers and the distinct numbers separated by exactly one space (i.e., if a number appears multiple times, it is displayed only once). (Hint: Read a number and store it to an array if it is new. If the number is already in the array, ignore it.) After the input, the array contains the distinct numbers. Here is the sample run of the program: Enter...
Write a Java program that reads two integers on the keyboard and displays them on the...
Write a Java program that reads two integers on the keyboard and displays them on the screen.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT