Question

In: Computer Science

write a program using the main method where the user enters a number greater than 0,...

write a program using the main method where the user enters a number greater than 0, and the program prints out a set of stairs. The stairs consist of 3 boxes stacked on top of each other where the length and width of the first box is the number, the length and width of the second box is the number plus 1, and the length and width of the third box is the number plus 2. The stairs should be drawn using asterisks.

Solution Tests:

  • Does the solution compile?
  • Does the solution have your name in the comments?
  • If the user enters 2, then does the program print out:

**

**

***

***

***

****

****

****

****

  • If the user enters 3, then does the program print out:

***

***

***

****

****

****

****

*****

*****

*****

*****

*****

  • If the user enters 4, does the program print out:

****

****

****

****

*****

*****

*****

*****

*****

******

******

******

******

******

******

PROVIDED CODE:

* Provided code. Do not alter the code that says "Do not alter"
 * Make sure this at least compiles (no syntax errors)
 * You may write additional methods to help
 */
//Do not alter-----------------------------------------------------------------------
import java.util.Scanner;
public class Question01 {

        public static void main(String[] args) {
                int number;//Used for the stairs
                if(args == null || args.length == 0)
                {
                        Scanner keyboard = new Scanner(System.in);
                        System.out.println("Enter the value to draw some stairs");
                        number = keyboard.nextInt();
                        keyboard.nextLine();
                }
                else
                {
                        number = Integer.parseInt(args[0]);
                }
//-----------------------------------------------------------------------------------
                //Write your solution here

                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
        }//Do not alter this
//Space for other methods if necessary-----------------------------------------------
        //Write those here if necessary
        
//-----------------------------------------------------------------------------------
}//Do not alter this

/*Solution Description
 * 
 */

Solutions

Expert Solution

Source Code:

Output:

Code in text format (See above images of code for indentation):

import java.util.Scanner;

/*class definition*/

public class Question01

{

    /*main method*/

    public static void main(String[] args)

    {

        int number;/*Used for the stairs*/

        if(args==null||args.length==0)

        {

            /*read value from user*/

            Scanner keyboard = new Scanner(System.in);

            System.out.println("Enter the value to draw some stairs");

            number=keyboard.nextInt();

            keyboard.nextLine();

        }

        else

        {

            /*convert to integer*/

            number=Integer.parseInt(args[0]);

        }

        /*using nested loops print 3 boxes*/

        /*outer loop iterates for 3 times for 3 boxes*/

        for(int i=0;i<3;i++)

        {

            /*below two loops prints a box of length and width*/

            for(int j=0;j<number;j++)

            {

                for(int k=0;k<number;k++)

                    System.out.print("*");

                /*new line*/

                System.out.println();

            }

            /*increment number for next iteration*/

            number+=1;

        }

    }

}




Related Solutions

Using the provided code (found here), write a program using the main method where the user...
Using the provided code (found here), write a program using the main method where the user enters Strings and the program echoes these strings to the console until the user enters “quit”. When user quits the program should print out, “Goodbye”. You may assume that the case is ignored when the user enters, “quit”, so “quit”, “QUIT”, “Quit”,“qUiT”, etc. are all acceptable ways to end the program. The results should be printed out to the console in the following format:...
Write a python program which asks the user to enter a positive number that is greater...
Write a python program which asks the user to enter a positive number that is greater than 30 called, “num2” and then does the following: o 1) Print all numbers between 1 and “num2” that are divisible by 2 and 3. o 2) Print all numbers between 1 and “num2” that are either divisible by 6 or 7. o 3) Print all numbers between 1 and “num3” that is not divisible by 5
write a program using the main method where it searches through an array of positive, non-zero...
write a program using the main method where it searches through an array of positive, non-zero integer values and prints out the maximum even and odd values. The program should use the array provided in the code, and you may assume that it has already been populated with values. The results should be printed out to the console in the following format: “Max Even: ”<<max even value>> “Max Odd: ”<<max odd value>> Values denoted in “<< >>” represent variable values,...
def main():     # keeping asking user for a word or name until user enters 0    ...
def main():     # keeping asking user for a word or name until user enters 0     while True:         word = input('Enter a word/name to convert (enter 0 to quit): ').upper()       if word == '0': break         print(convert_to_soundex(word)) Whenever i try to run the program it tells me unintend doesn't match any outer identation level !!!!
Java Program 1. Write a program that asks the user: “Please enter a number (0 to...
Java Program 1. Write a program that asks the user: “Please enter a number (0 to exit)”. Your program shall accept integers from the user (positive or negative), however, if the user enters 0 then your program shall terminate immediately. After the loop is terminated, return the total sum of all the previous numbers the user entered. a. What is considered to be the body of the loop? b. What is considered the control variable? c. What is considered to...
Count the number of 1’s and 0’s Write a MIPS program that will ask the user...
Count the number of 1’s and 0’s Write a MIPS program that will ask the user to enter an integer, and then output the number of 1’s and 0’s that are present in the integer’s signed 32-bit binary representation. For example, 15 has a binary representation of 0000 0000 0000 0000 0000 0000 0000 1111, which has 28 zeroes and 4 ones. We have provided you the starter code that deals with the input/output logic. The integer input is saved...
Write a C++ program that reads numbers from the user until the user enters a Sentinel....
Write a C++ program that reads numbers from the user until the user enters a Sentinel. Use a Sentinel of -999. Ignore all negative numbers from the user input. Do the following: Output the sum of all even numbers Output the sum of all odd numbers Output the count of all even numbers Output the count of all odd numbers You must use loops and numbers to do this. You must not use any arrays or vectors for this program.
Write a program using switch statement that asks user to enter the month number and then...
Write a program using switch statement that asks user to enter the month number and then it prints out the number of days for that month. For simplicity reasons have your program print 28 days for February no matter if it is a leap year or not. Your program should also handle any invalid month numbers that user could enter (hint use default for the switch). Use a while loop to allow user to test for different month entries till...
Write a program using a Scanner that asks the user for a number n between 1...
Write a program using a Scanner that asks the user for a number n between 1 and 9 (inclusive). The program prints a triangle with 2n - 1 rows. The first row contains only the square of 1, and it is right-justified. The second row contains the square of 2 followed by the square of 1, and is right justified. Subsequent rows include the squares of 3, 2, and 1, and then 4, 3, 2 and 1, and so forth...
Write a program that contains a main method and another method named userName. The main method...
Write a program that contains a main method and another method named userName. The main method should prompt the user to enter a full name. The userName method takes the full name as an argument and prints the name in reverse order and returns the number of characters in the name. See Sample Output (input shown in blue). Sample Output Please enter your FULL name Billy Joe McCallister Here is the name Billy Joe McCallister in reverse: retsillaCcM eoJ ylliB...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT