Question

In Chapter 1 you created a program named Triangle in which you displayed a seven-line triangle...

In Chapter 1 you created a program named Triangle in which you displayed a seven-line triangle pattern like the one in Figure 6-33 by using a series of println() statements. Now, using your knowledge of loops, revise the program so that it contains no more than three output statements.

class TriangleWithLoops {
public static void main(String[] args) {
// Write your code here
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
class TriangleWithLoops {
    public static void main(String[] args) {
        for (int i = 0; i < 7; i++) {
            for (int j = 0; j <= i; j++) System.out.print("*");
            System.out.println();
        }
    }
}

Add a comment
Know the answer?
Add Answer to:
In Chapter 1 you created a program named Triangle in which you displayed a seven-line triangle...
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
  • 1 Problem Description Instructions. You are provided one skeleton program named LCS.java . The source files...

    1 Problem Description Instructions. You are provided one skeleton program named LCS.java . The source files are available on Canvas in a folder named HW6 . Please modify the skeleton code to solve the following tasks. • Task 1 (100 pts). Implement the lcs length() function as discussed in Lecture 11. • Note: You should not return the double-array b and c as in the pseu- docode. Instead, return the length of the longest common subsequence. • Hint: To get...

  • Help with program /* Lab 7, Part E: Created by Celine Latulipe public class Lab7Parte {...

    Help with program /* Lab 7, Part E: Created by Celine Latulipe public class Lab7Parte { public static void main(String [] args) // TODO: put your code here to generate a random number between 0 and 20 // and then print out that many asterisks on a single line. { بہا } We were unable to transcribe this image/* Lab 7, Part F: Created by Celine Latulipe public class Lab 7PartF { public static void main(String [] args) { //...

  • Java 1. Create an application named NumbersDemo whose main() method holds two integer variables. Assign values...

    Java 1. Create an application named NumbersDemo whose main() method holds two integer variables. Assign values to the variables. In turn, pass each value to methods named displayTwiceTheNumber(), displayNumberPlusFive(), and displayNumberSquared(). Create each method to perform the task its name implies. 2. Modify the NumbersDemo class to accept the values of the two integers from a user at the keyboard. This is the base code given: public class NumbersDemo { public static void main (String args[]) { // Write your...

  • you created an application named QuartsToGallonsInteractive that accepts a number of quarts from a user and...

    you created an application named QuartsToGallonsInteractive that accepts a number of quarts from a user and converts the value to gallons. Now, add exception-handling capabilities to this program and continuously reprompt the user while any nonnumeric value is entered. // QuartsToGallonsInteractive.java import java.util.Scanner; class QuartsToGallonsInteractive {    public static void main(String[] args)    {       final int QUARTS_IN_GALLON = 4;       int quartsNeeded = 18;       int gallonsNeeded;       int extraQuartsNeeded;       Scanner input = new Scanner(System.in);       System.out.print("Enter quarts...

  • Coding for MindTap C# Programming Exercise 7-1. Create a program named SalesLetter whose Main() method uses...

    Coding for MindTap C# Programming Exercise 7-1. Create a program named SalesLetter whose Main() method uses several WriteLine() calls to display a sales letter to prospective clients for a business of your choice. Display your contact information at least three times in the letter. The contact information should contain at least three lines with data such as land line phone number, cellphone number, email address, and so on. Each time you want to display the contact information, call a method...

  • Question 1[JAVA] Add a method in the Main class named getLines() that takes a filename as...

    Question 1[JAVA] Add a method in the Main class named getLines() that takes a filename as a String and returns each line in the file in an array. Have each element of the array be a String. Do not include the newline at the end of each line. Use a BufferedReader object to read the file contents. Note, the contents of input.txt will be different (including the number of lines) for each test case. Example: getLines( "input.txt" ) returns (an...

  • Language is Java. Thank you.It is a review test and I will find out the rest...

    Language is Java. Thank you.It is a review test and I will find out the rest if I just know that answers. 1) What is the output of the following code: public class Test public static void main(String] args) [ String s1 new String("Java String s2 new String("Java) System.out.print( (s1 s2)(s1.equals (s2))) A) false false B) true true C) false true D) true false E) None of the above 2) Given the following program: public class Test f public static...

  • In this assignment you will be writing multiple methods that work with arrays. These methods will...

    In this assignment you will be writing multiple methods that work with arrays. These methods will perform specific functions and, in most cases, return results. Your class should be named Grades. Your program will have the following methods: public static void rotateElements(int[] arr) public static void rotateElements(int[] arr, int rotationCount) public static void reverseArray(int[] arr) public static void main(String[] args)

  • Please put both of this loops into one program. Set it up so that there is...

    Please put both of this loops into one program. Set it up so that there is one main function and both loops are within it. Thank You. import java.util.Scanner; public class WhileDavidMungomaLab12 { public static void main(String[] args) { int aScore = -1; while (aScore < 0 || aScore > 100) { Scanner sc = new Scanner(System.in); System.out.println("Please enter a valid number that is within the specified range(0 and 100): "); aScore = sc.nextInt(); } } } AND import java.util.Scanner;...

  • write a static method named greet that takes a String that represents a name and prints...

    write a static method named greet that takes a String that represents a name and prints a personalized greeting to StdDraw. So far i have in the main method... 4 public class TakeHomeAssignment 5 { 6 public static void main(String[] args) 7 { 8 StdDraw.setScale(0,500); 9 //drawEye(250,250,50); 10 String greet(Aaron); 11 // drawStickFigure(250,250); and for the method; //public static String greet( name) 31 //{ 32 33 34 //StdDraw.text(250,250,"Hello" +name); 35 36 // } Im getting errors saying its an illegal...

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