# Write the definition of a method max that has three int parameters and returns the largest?

535 views

## Problem:

I am new to programming, so need query to get  query to return max number from 3 integer?

Write the definition of a method max that has three int parameters and returns the largest?

Can anyone guide with correct code?

## Solution:

You can try some of the approaches, yo can get solution to your query:

``````public static int max(int a, int b, int c)
{
return Math.max(Math.max(a,b),c);
}``````

or

``````int max (int a,int b,int c)
{if (a>b && a>c) return a;
else if (b>c) return b;
else return c;}``````

Hope you can get right output with this query.

## Solution:

The solution of this question is

``````public static int max(int a, int b, int c)
{
return Math.max(Math.max(a,b),c);
}``````

### or You can attempt this method

``````public static int max(int a, int b, int c) {
return a > b && a > c ? a : b > a && b > c ? b : c > a && c > a ? c : a;
}``````

### or,

``````
public int max (int aint, int bint, int cint){
return Math.max(aint, Math.max(bint, cint));
}``````

## Related questions

102 views
Problem: Hi there! I am new to the world of programming. My programming teacher gave me an assignment in which I have to write a program in which there would be a function that will take two strings as input from user and will compare the size of both strings ... the larger string of the two. I have no clue how to do that. Please provide me with the sample program with proper description. Thanks
77 views
Problem: I have recently learned about the functions in C++ and I want to write a function that has three string parameters and returns the smallest string of all according to its length. How can I do that? This question might seem nonsense so I apologize for being so dumb. Thanks!
179 views
I'm new in java programming, I know how to find out the largest or smallest number from an array. But I'm facing problem when I'm trying to find out smallest staring in 3 string. Please help me write a method min that has three string parameters and returns the smallest.
1 vote
8 views
Problem: I&rsquo;ve got a project in which I have to create a project which can take 3 integers and return the smallest one . You muse use Math class min function .
178 views
I start programming recently and I love to do programming but every day I'm facing new problems. I wrote a java code where I can easily take two int input from a user and I'm able to print the smallest value. But I'm doing all things in the main method. I don't want to do ... smallest; if(a>b){ smallest = b; }else{ smallest = a; } System.out.println("Smallest is: "+smallest); } Here is my code.
29 views
Problem: I want to write a function that receives two pointers to functions and returns a pointer to the function composicion. Is it possible to do that? This was my idea: typedef int (* integerFunction) (int); integer function composition (integer function f1, integer function f2) { return f1 (f2); }
15 views
Problem: Would the following code be correct? class Person { private: string name; bool sex; int age; public: Person (); bool getSexo (); int getAge (); Person play (string s); }Hope someone could help me out?