Question

In: Computer Science

Write a program that produces the following output using nested for loop in Java. ****** ////////////...

Write a program that produces the following output using nested for loop in Java.

****** //////////// ******

***** //////////\\ *****

**** ////////\\\\ ****

*** //////\\\\\\ ***

** ////\\\\\\\\ **

* //\\\\\\\\\\ *

\\\\\\\\\\\\

Solutions

Expert Solution



public class NestedLoops {

    public static void main(String[] args) {
        // change these variables if you want some other pattern
        int numStars = 6;
        int numForwardSlashes = 12;
        int numBackwardSlashes = 0;
        int numLines = 3;

        for (int i = 0; i < numLines; i++) {
            for (int j = 0; j < numStars; j++) {
                System.out.print("*");
            }
            System.out.print(" ");
            for (int j = 0; j < numForwardSlashes; j++) {
                System.out.print("/");
            }
            for (int j = 0; j < numBackwardSlashes; j++) {
                System.out.print("\\");
            }
            System.out.print(" ");
            for (int j = 0; j < numStars; j++) {
                System.out.print("*");
            }
            System.out.println();
            numStars--;
            numForwardSlashes -= 2;
            numBackwardSlashes += 2;
        }
    }
}


Related Solutions

In Java: Write a nested loop that allows the user to continuously enter phrases and output...
In Java: Write a nested loop that allows the user to continuously enter phrases and output underscores for each character of the phrase. End when the user enters "done" (ignoring case). Once you have this completed, modify your code so that if the character is whitespace, you print a space " " instead of an underscore - Hint: use Character.isWhitespace(YOURCHARHERE) //returns a boolean.
Write a java program: Write a nested loop program creating an array list of three positions.  The...
Write a java program: Write a nested loop program creating an array list of three positions.  The first loop terminates with a sentinel value of which user is prompted for input to continue of quit.   Inside loop to enter in each position a prompted input of person's first name.  After the inside loop, edit the second array location making its value "Boston". Print the array's contents.
must use python Write a nested for loop that displays the following output using the same...
must use python Write a nested for loop that displays the following output using the same integer from part a:                                                     1                                                 1   2   1                                             1   2   4   2   1                                         1   2   4   8   4   2   1                                     1   2   4   8 16   8   4   2   1                                 1   2   4   8 16 32 16   8   4   2   1                             1   2   4   8 16 32 64 32 16   8   4   2   1                         1   2   4  ...
Using Matlab Write a program that print the following matrix. (hint: use nested for-loop and if-statement)...
Using Matlab Write a program that print the following matrix. (hint: use nested for-loop and if-statement) mat = [2 -1 0 0 0 -1 2 -1 0 0 0 0 -1 2 -1 0 0 0 -1 2];
IN JAVA Create a program that uses a nested for loop to display a rectangle of...
IN JAVA Create a program that uses a nested for loop to display a rectangle of #'s with a given number of rows and columns,. This should only display the # when the column is an odd number (see examples below). Get the number of rows and columns from the user, and display the result. Examples: If the user provided rows=4, and columns=7, the program should display a pattern as follows: # # # # # # # # #...
JAVA CODE, USE FOR LOOP PLEASE Using the PurchaseDemo program and output as your guide, write...
JAVA CODE, USE FOR LOOP PLEASE Using the PurchaseDemo program and output as your guide, write a program that uses the Purchase class to set the following prices, and buy the number of items as indicated. Calculate the subtotals and total bill called total. Using the writeOutput() method display the subtotals as they are generated as in the PurchaseDemo program. Then print the total bill at the end Use the readInput() method for the following input data Oranges: 10 for...
For this assignment you will write a Java program using a loop that will play a...
For this assignment you will write a Java program using a loop that will play a simple Guess The Number game. Create a new project named GuessANumber and create a new Java class in that project named GuessANumber.java for this assignment. The program will randomly generate an integer between 1 and 200 (including both 1 and 200 as possible choices) and will enter a loop where it will prompt the user for a guess. If the user has guessed the...
Your objective is to write a well-documented simple program using classes, a loop, and nested ifs...
Your objective is to write a well-documented simple program using classes, a loop, and nested ifs to simulate an ATM using JAVA. 1. Create an ATM class with class variables name, pin, and balance, a constructor with parameters to assign values to the three instance variables, methods to get the name, pin, and balance, and methods to handle validated deposits and withdrawals ( deposit and withdrawal amounts cannot be negative, and withdrawal amount must not be greater than the existing...
Using a while loop. Write a JAVA program that asks a user for an integer between...
Using a while loop. Write a JAVA program that asks a user for an integer between 1 and 9. Using the user input, print out the Fibonaccci series that contains that number of terms. Sample output: How many terms would like printed out for the Fibonacci Sequence? 7 Fibonacci Series of 7 numbers: 0 1 1 2 3 5 8
Write a Java program using using WHILE loop to find the sum of all integers between...
Write a Java program using using WHILE loop to find the sum of all integers between 200 to 250 which are divisible by 7. Sample Output: Numbers between 200 and 250, divisible by 7: 203 210 217 224 231 238 245 The sum is: 1568
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT