Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.
public int intMax(int a, int b, int c) {
if(a>b)
{
int minValue=Math.min(a,b);
return a;
}
if(a>c)
{
int minValue=Math.min(a,c);
return a;
}
if(b>c)
{
int minValue=Math.min(b,c);
return b;
}
return c;
}
public int intMax(int a, int b, int c) {
if((a>b)&(a>c))
{
//int minValue=Math.min(a,b);
return a;
}
if(b>c)
{
//int minValue=Math.min(a,c);
return b;
}
return 0;
/*if(b>c)
{
int minValue=Math.min(b,c);
return b;
}
return c;
}*/
}
public class Test4 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int largeValue=intMax(5,6,2);
System.out.println("largeValue is--->"+largeValue);
}
public static int intMax(int a, int b, int c) {
if((a>b)&(a>c))
{
//int minValue=Math.min(a,b);
return a;
}
if(b>c)
{
//int minValue=Math.min(a,c);
return b;
}
return 0;
/*if(b>c)
{
int minValue=Math.min(b,c);
return b;
}
return c;
}*/
}
}
public int intMax(int a, int b, int c) {
return Math.max(Math.max(a,b),c);
}
You can do it with nine applications of the Math.max function.
Let us say if i have 10 given int numbers (instead of 3 in this case) can i find the largest of the 10 using Math.max function. Please advise
public int intMax(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8, int p9, int p10) {
return Math.max(Math.max(Math.max(Math.max(Math.max(Math.max(Math.max(Math.max(Math.max(p1,p2),p3), p4),p5),p6),p7),p8),p9),p10);
}
public class Test6 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] values = {12,45,23,67,45,86,43,67,98,5,45,345,67,89,34,56};
int maxval = values[0];
for (int ind=1; ind < values.length; ind++) {
maxval=Math.max(maxval, values[ind]);
}
System.out.println("Max Value : " + maxval);
}
}
public class Test7 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int largeValue=intMax(5,6,8);
System.out.println("largeValue is--->"+largeValue);
}
public static int intMax(int a, int b, int c) {
if((a>b)&&(a>c))
{
//int minValue=Math.min(a,b);
return a;
}
if(b>c)
{
//int minValue=Math.min(a,c);
return b;
}
return c;
}
}
That scenario is covered. Try it with your test data to validate.
i validated with test data and works fine. But i did not understand how that scenario is covered. Please advise
Those results are not unexpected.
Did you have reason to think it would do something different?
public static int intMax(int a, int b, int c) {
if ((a>b)&&(a>c)) { // a is bigger than b and bigger than c...
return a; // ...so return it
}
// If you're here, you already know that a is not the biggest one, so let's focus on b and c
if (b>c) { // b is bigger than c...
return b; // ... so return b
}
// if you're here, you know that a is not the biggest, b is not the biggest, so...
return c; // c must be the biggest. Well, return it.
}
public static int intMax(int a, int b, int c) {
if ((a>b)&&(a>c)) {
return a;
} else if (b>c) {
return b;
} else {
return c;
}
}
if a > b and a > c then return a
if b > c then return b else return c