1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Andrew [12]
2 years ago
8

Write a method, findMax(), that takes in two integers and returns the largest value. Ex: If the program input is: 4 2 the method

findMax() returns: 4 Note: Your program must define the method: public int findMax(int num1, int num2)
Computers and Technology
1 answer:
olya-2409 [2.1K]2 years ago
4 0
<h2>Answer:</h2><h2></h2>

public int findMax(int num1, int num2){

      if(num1 > num2){

           return num1;

      }

 

      else {

          return num2;

      }

}

<h2>Explanation:</h2>

<em></em>

The code has been written in Java and the following explains every part of the code.

<em>i. Start with the method header:</em>

<em>public int findMax(int num1, int num2)</em>

<em>ii. Followed by a pair of curly braces representing the block for the method.</em>

<em>public int findMax(int num1, int num2){</em>

<em>     </em>

<em>}</em>

<em />

<em>iii. Within the block, write the statements to find out which is greater between num1 and num2</em>

This is done with an if..else statement. To check if num1 is greater than num2, write the following within the block.

<em>if(num1 > num2){</em>

<em>    return num1;</em>

<em>}</em>

<em>else {</em>

<em>  return num2;</em>

<em>}</em>

<em />

The if block tests if num1 is greater than num2. If it is, then num1 will be returned.

The else block is executed only if num1 is not greater than num2. In this case, num2 will be returned since it is greater.

<em>iv. Put all together</em>

<em>public int findMax(int num1, int num2){</em>

<em>    if(num1 > num2){</em>

<em>        return num1;</em>

<em>    }</em>

<em>   else {</em>

<em>       return num2;</em>

<em>    }</em>

<em>}</em>

<em />

<em />

<em />

You might be interested in
The movie polar express was critically acclaimed due to the unbelievably lifelike movements of Tom Hanks character
Fed [463]
I think it is greyhound
6 0
2 years ago
What is the python print of (“5”+”7”)?
Firdavs [7]

Answer:

57

Explanation:

Since the 5 and the 7 don't represent integers instead they represent strings so it would come out as 57 hope I helped!

4 0
3 years ago
Um i'm new here... and i don't know really how to use this... i was wondering if som 1 can help me
blagie [28]

Shining and warm

Collapse 3

JOJO

fate series

Bungou Stray Dog

EVA

Dao Master

Alien invasion

Future diary

Fate of Space

Story Series

Beyond the Boundary

Bayonetta

Onmyoji

Full-time master

How to develop a passerby heroine

Illusion Front

Psychometer

your name

Noragami

One Piece

Senran Kagura

Attacking Giant

Kabaneri of the Iron Fortress

Violet Evergarden

Demon Slayer

Under one person

Guilt crown

Black reef

Star Cowboy

Black Street Duo

Aria the Scarlet Ammo

Hatsune Miku

The last summoner

re creator

Detective Conan

Naruto

grim Reaper

Tokyo Ghoul

Song of Hell

At the beginning

Sword Art Online

Girl opera

Hakata pork bones pulled dough

Sunny

Black bullet

Trembling

On the broken projectile

Black Butler

Destiny's Gate

Persona

God Prison Tower

April is your lie

Ground-bound boy Hanako-kun

League of legends

Clever girl will not get hurt

Tomorrow's Ark

DARLING in the FRANKXX

RWBY

Little Busters

dating competition

Gintama

One Punch Man

The promised neverland

Taboo curse

God of college

Queen of Arms

Sword Net 3

Final fantasy

6 0
3 years ago
Read 2 more answers
Which of these is NOT one of the three parts to the event-handling mechanism in Java?
Tamiku [17]

Answer:Event action

Explanation:Event-handling mechanism is the technique through which the  the management of any event is Java is controlled and coordinated. The event handler code is used for the managing of the mechanism and execution.

Event action is not a part of the event handling mechanism in the java because no such step comes under the code of event handler and rest other option are present in java event handler.

5 0
3 years ago
Write a program that defines an interface having the following methods: addition, subtraction, multiplication, and division. Cre
Tatiana [17]

Hello, you haven't provided the programing language in which you need the code, I'll explain how to do it using Python, and you can follow the same logic to make a program in the programing language that you need.

Answer:

1. # -*- coding: utf-8 -*-

2. #Python  

3. class Calculator:

4.     def add(self):

5.         print(a + b)

6.     def sub(self):

7.         print(a - b)

8.     def mul(self):

9.         print(a * b)

10.     def div(self):

11.         print(a / b)

12.  

13. obj = Calculator()

14. choice = 1

15. while choice != 0:

16.     a = int(input("\nEnter first number: "))

17.     b = int(input("Enter first number: "))

18.      

19.     print("\n0. EXIT")

20.     print("1. DIVISION")

21.     print("2. ADDITION")

22.     print("3. SUBTRACTION")

23.     print("4. MULTIPLICATION")

24.      

25.     choice = int(input("\nEnter your choice: "))

26.     if choice == 1:

27.         obj.div()

28.     elif choice == 2:

29.         obj.add()

30.     elif choice == 3:

31.         obj.sub()

32.     elif choice == 4:

33.         obj.mul()

34.     else:

35.         break

Explanation:

  • From lines 1 to 12 we define the object with four methods, addition, subtraction, multiplication, and division. Each method contains the operation between two variables inside a print function
  • On line 13 we instantiate our class
  • On line 14 we declare the variable choice that is going to store the operation that the user wants to perform
  • On line 15 we declare a while loop, this is going to keep running the program until the user wants to exit
  • From line 16 to 18 we ask the user to enter two numbers
  • From line 19 to 24 we print the possible operation, assigning a number for each operation, this indicates to the user what number to press for what operation
  • On line 25 we ask the user for the operation
  • From lines 26 to 35 we check the user input an accordingly we call the corresponding method to performs the operation
7 0
3 years ago
Other questions:
  • darren wants to substitute every occurence of the word bulky in his spreadsheet with the word strong. which of these options sho
    9·2 answers
  • For Excel:
    5·1 answer
  • One of the best ways to shoot a picture is to frame the subject in the middle of the screen or viewer. T or F
    14·2 answers
  • Write a program to read from std_info.txt.
    11·1 answer
  • CORRECT ANSWER GETS BRAINLIEST
    8·2 answers
  • What is said to be the first mechanical calculator​
    7·2 answers
  • What is the code for this please?​
    13·1 answer
  • Which family does Ms word 2007 belongs to?​
    6·2 answers
  • Is majority intent determined by how many times the same type of result is shown on the search engine result page?
    6·1 answer
  • Game Design!
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!