Question

Complete these two patterns in program using nested Loops for each. You MUST use nested loops...

Complete these two patterns in program using nested Loops for each. You MUST use nested loops in this one. You are demonstrating how to use loops to make a pattern.

Pattern 1

&

&&

&&&

&&&&

&&&&&

Pattern 2

&&&&&

&&&&

&&&

&&

&

Use introductory level Java to solve this and NetBeans 8.0

Homework Answers

Answer #1
public class PrintPatterns {

    public static void main(String[] args) {
        System.out.println("Pattern 1");
        for (int i = 1; i <= 5; i++) {
            for (int j = 0; j < i; j++) {
                System.out.print("&");
            }
            System.out.println();
        }
        System.out.println("Pattern 2");
        for (int i = 5; i >= 1; i--) {
            for (int j = 0; j < i; j++) {
                System.out.print("&");
            }
            System.out.println();
        }
    }
}

Know the answer?
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
Similar Questions
Print the following two patterns using nested loops. Pattern 1 13579 13579 13579 13579 Pattern 2...
Print the following two patterns using nested loops. Pattern 1 13579 13579 13579 13579 Pattern 2 #####1 ####12 ###123 ##1234 #12345
C++. Write a program that uses nested while loops or for statements to display Pattern A...
C++. Write a program that uses nested while loops or for statements to display Pattern A below, followed by an empty line and then another set of loops that displays Pattern B. Once again no setw implementation is allowed here and you must use appropriate control structures with proper indentation to generate these static patterns. Use meaningful variable identifier names, good prompting messages and appropriate comments for each loop segment as well as other sections in the body of your...
PYTHON 1.      Complete the attached template program pattenrs.py to create and display a number of patterns. The...
PYTHON 1.      Complete the attached template program pattenrs.py to create and display a number of patterns. The program works with a single digit. The default value is 6, but user to change it as a menu selection. 2.      Program should display the patterns below. Additionally, you need to create your own pattern. 3.      Do not modify myPatterns6 driver. 4.      Make sure you document the program and its functions. 5.      PatternI is already implemented. 6.      Create five additional functions (similar to PatternI function) to implement Patterns II,...
Summary In this lab, you add nested loops to a Java program provided. The program should...
Summary In this lab, you add nested loops to a Java program provided. The program should print the letter E. The letter E is printed using asterisks, three across and five down. Note that this program uses System.out.print("*"); to print an asterisk without a new line. Instructions Write the nested loops to control the number of rows and the number of columns that make up the letter E. In the loop body, use a nested if statement to decide when...
Write a Java program using a single multi-level nested for-loop to display the following pattern (For...
Write a Java program using a single multi-level nested for-loop to display the following pattern (For each iteration, only one character can be printed) : 1,2,3,4,5,6,7,8,9#1,2,3,4,5,6,7,8,9#1,2,3,4,5,6,7,8,9# 3,6,9,12,15,18,21,24,27#3,6,9,12,15,18,21,24,27#3,6,9,12,15,18,21,24,27# 5,10,15,20,25,30,35,40,45#5,10,15,20,25,30,35,40,45#5,10,15,20,25,30,35,40,45#
In C# using the Console App (.NET FRAMEWORK) Create and test a Windows Console application that...
In C# using the Console App (.NET FRAMEWORK) Create and test a Windows Console application that displays the following patterns separately, one after the other. You MUST use nested for loops to generate the patterns, like the example in the PowerPoint slides from this chapter. All asterisks (*) should be displayed by a single statement of the form Console.Write("*"); which causes the asterisks to display side by side. A statement of the form Console.WriteLine(); can be used to move to...
(AdditionTable.java) Write a program that displays the following addition table. Notes: You must use a nested...
(AdditionTable.java) Write a program that displays the following addition table. Notes: You must use a nested loop. There are spaces at the beginning of each row.
Java Draw something pretty using ASCII art, subject to a few constraints. Please feel free to...
Java Draw something pretty using ASCII art, subject to a few constraints. Please feel free to use your imagination as much (or as little) as you like. Your program must use class constants (e.g., static final int SIZE=10) in place of any numeric constants (except for 0 and 1), and in place of any character constants. Your program must use at least 3 nested loops. At least one of the three must be a doubly-nested loop (a for loop inside...
Use nested loops to write a function called substring(s,b) that returns True or False depending on...
Use nested loops to write a function called substring(s,b) that returns True or False depending on whether or not b is a substring of s. A substring is a series of characters which appears inside another word in the exact same order. For example, substring(“banana”, “ana”) should return True whereas substring(“banana”,”bna”) should return False. Use this function to write a program that asks the user for a string s and a substring b and prints whether b is a substring...
PLEASE USE LOOPS ONLY TO COMPLETE THIS ASSIGNMENT. (Find the three lowest scores) Write a program...
PLEASE USE LOOPS ONLY TO COMPLETE THIS ASSIGNMENT. (Find the three lowest scores) Write a program that prompts the user to enter the number of students and each student’s name and score, and finally displays the student with the lowest score and the student with the second-lowest score and the student with the third lowest score. Program must accept first name only or first and last name SAMPLE RUN #1: java ThreeLowestScores   Enter the number of students:6↵ Student 1 of...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT