Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help writing this in Java Write a program that will have the following methods, each of which will be called from the main

I need help writing this in Java

Write a program that will have the following methods, each of which will be called from the main method.

Method 1: Call this method displayTriangle, which will return nothing and will take an integer argument.

The method will display a triangle like the following:

*

**

***

****

*****

The height of the triangle will be controlled by the integer argument. So, here is what you have to do:

1. In your main method, ask the user to enter a number for the height of the triangle.

2. Call the displayTriangle method by passing the user entered number as the argument.

Method 2: Call this method printOdd, which will return nothing and will take two integer arguments. This method will display all odd numbers between those two numbers passed through the argument. Here is what you have to do:

1. In your main method ask the user to enter the starting number and put it in a variable.

2. Again in your main method, ask the user to enter the ending number and put it in a variable.

3. Call the printOdd method by passing the user entered numbers as the arguments.

Method 3: Call this method printSum, which will return an integer and will take one integer argument. This method will return the sum of all numbers from 1 to that integer number passed as argument. So, here is what you have to do:

1. In your main method, ask the user to enter a number that you want to sum up to from 1.

2. Call the printSum method by passing the user entered number as the argument and save the return value from that method in an integer variable.

3. Print that variable (which holds the return value from the method) in the screen.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions