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
Programming challenge description: Write a program that, given two binary numbers represented as strings, prints their sum in bi
Lubov Fominskaja [6]

Answer:

The program to this question can be given as:

Program:

#include<iostream>  //include header file

using namespace std;  

string add(string a, string b)  //define add function

{       //declare variable  

   string result = "";  

   int sum = 0,k,l;      

   cahr x;    

   k= a.size() - 1;

   l = b.size() - 1;  

   while (k>= 0 || l>= 0 || sum == 1) //loop

   {

   //addition 

       sum= sum+ ((k >= 0)? a[k] - '0': 0);  

       sum= sum+ ((l >= 0)? b[l] - '0': 0);

        x=sum%2;

      result=(x+'0') +result;

  // Compute carry

       sum =sum/ 2;  

       // Move to next digits  

       k--;  

       l--;  

   }  

   return result; //return value

}

int main()  //main method  

{  

   string a,b;  //string variable

   cout<<"Enter first binary digit: ";  //message.

   cin>>a;     //input from user

   cout<<"Enter Second binary digit: ";  //message.

   cin>>b;     //input from user

   cout <<"Addition :"<<add(a, b)<<endl; //print addition

   return 0;  

}

Output:

Enter first binary digit: 1101

Enter Second binary digit: 100

Addition :10001

Explanation:

In the above c++ program first, we include the header file. Then we define the add function in the add function we add two binary digits by passing value as arguments. In this function, we define a variable that is used on the addition of binary numbers. In this function we define the loop in the loop we check if two binary number is 1 then it will print 0 and pass 1 as the carry. after performing addition it will return value. In the main function, we take two binary numbers from the user and pass the value to the function and print function return value.

8 0
3 years ago
What is the name given to software that decodes information from a digital file so that a media player can display the file? har
KiRa [710]

Answer:

plug-in

Explanation:

A Plug-in is a software that provides additional functionalities to existing programs. The need for them stems from the fact that users might want additional features or functions that were not available in the original program. Digital audio, video, and web browsers use plug-ins to update the already existing programs or to display audio/video through a media file. Plug-ins save the users of the stress of having to wait till a new product with the functionality that they want is produced.

6 0
2 years ago
To add a hyperlink to your presentation, select the text, choose Hyperlink from the Insert menu, and then
Elan Coil [88]

Answer:

I guessed D, taking it right now, sorry if it's wrong

Explanation:

6 0
2 years ago
Complete the statement about WYSIWYG editors when you use a WYSIWYG editor you typically specify the continent and blank A.layou
erastovalidia [21]

Answer:

When you use a WYSIWYG editor you typically specify the content and layout while the editor generates the HTML code

Explanation:

Required

Complete the blanks

In WYSIWYG, the user of the application provides contents to the WYSIWYG software and also designs the appearance; The appearance is referred to as the layout.

Throughout the design, the user will not use HTML codes; it is the duty of the WYSIWYG editor to generate HTML code based on the input designs by the user.

6 0
3 years ago
Help pls nnnnnnnnnnnnnnnnnnnn
kiruha [24]

Answer:

3rd choice

Explanation:

i did that yesterday

5 0
3 years ago
Other questions:
  • Writenames of eight output device.​
    8·1 answer
  • The part of the computer that contains the brain or the Central Park nursing unit is also known as
    10·1 answer
  • What can be designed to create annoying glitches or destroy data
    11·1 answer
  • 17. When an industrial electrical circuit requires a 220 VAC single phase power supply, the electric power supply circuit is nor
    7·1 answer
  • Freeeee BRAINLIESTHBJHBJHB
    8·2 answers
  • Write a program. Commence the change to be dispensed from a vending machine. An item machine can cost between $0.25 send a dolla
    9·1 answer
  • ....is an act of introducing an invention into market on business basis for profit​
    12·1 answer
  • Please please help I don’t understand this please.
    11·1 answer
  • How many hours do you spend on the Internet per day?
    11·2 answers
  • What are 2 ways to send a message to your client when signed in as an accountant user?.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!