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 C++ program to allow a user to enter in any positive number greater than...
Write a C++ program to allow a user to enter in any positive number greater than or equal to zero. The program should not continue until the user has entered valid input. Once valid input has been entered the application will determine if the number is an abundant number or not and display whether or not the number is an abundant number. If the user enters in a 0 the program should quit. An abundant number is a number n...
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 . Ask the user to enter a number less than 100. Test...
write a c++ program . Ask the user to enter a number less than 100. Test the input to make sure it is correct, and use a while loop to continuously ask the user for correct input value if they don't follow the input rule. After receiving the correct input, test the number to see if it is even or odd. If it is odd, use a while loop to do the following: Output to the monitor all odd numbers...
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 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 (other than the sentinel). Do the following: 1. Output the sum of all even numbers 2. Output the sum of all odd numbers 3. Output the count of all even numbers 4. Output the count of all odd numbers You must use alternation ('if' statements), loops and simple calculations to do...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT