Skip to content

Instantly share code, notes, and snippets.

@laxmankumar2000
Created April 20, 2021 10:43
Show Gist options
  • Save laxmankumar2000/99a7d2d3541310d29c4f0f391ae1f00d to your computer and use it in GitHub Desktop.
Save laxmankumar2000/99a7d2d3541310d29c4f0f391ae1f00d to your computer and use it in GitHub Desktop.
Program
package Contest1;
/*
Program1
Find a key??
You are provided with 3 numbers : input1 , input2 input 3;
each of these are four digit numbers within the range >==1000 and 9999,
you are expected to find the key using the below formula;
key == (sum of largest digits of all the 3 numbers ) + (sum of smallest digits of all 3 numbers)
for e.g. = input1 = 3521 ; input2 = 2452 \, input3 = 1352, they
key = (5+5+5) + (1+2+1)
key = 19;
*/
public class pg1 {
//Max method
static int MaxFind(char ch1[])
{
int max = ch1[0]; // sir mene ise jb debug kiya to ye max ko 51 le rha h
for (int i =0; i<ch1.length;i++)
{
if (ch1[i]>max)
{
max = ch1[i];
}
}
return max; // or return 53 kr rha h jb ki use 5 return krna tha.....
}
//Min method
static int MinFind(char arr11[])
{
int min = arr11[0];
for (int i =0; i<arr11.length;i++)
{
if (arr11[i]>min)
{
min = arr11[i];
}
}
return min;
}
public static void main(String[] args) {
//all 3 inputs
int input1 = 3521;
int input2 = 2452;
int input3 = 1352;
//convert into array of input1
String str1 = "" ;
str1 = String.valueOf(input1);
char ch1[];
ch1 = str1.toCharArray();
//convert into array of input2
String str2 ="";
str2 = String.valueOf(input2);
char ch2[];
ch2 = str2.toCharArray();
//convert into array of input3
String str3 ="";
str3 = String.valueOf(input2);
char ch3[];
ch3 = str3.toCharArray();
//for input1 to get max and min value
int max1 = MaxFind(ch1);
System.out.println(max1); // or iska ans 51 de rha h jb ki iska ans 5 anana chahiye ....
int min1 = MinFind(ch1);
//for input2 to get max and min value
int max2 = MaxFind(ch2);
int min2 = MinFind(ch2);
//for input3 to get max and min value
int max3 = MaxFind(ch3);
int min3 = MinFind(ch3);
//Now our key is
int key = ((max1+ max2 + max3 ) + (min1 + min2 + min3));
System.out.println("our key is " + key);
char arr10[] = {2,5,7,6,3,1} ;
//
System.out.println(MaxFind(arr10)); // sir ise mene jab max function kiya tb ans shi aaa rha h ans == 7
// System.out.println(" max " + max);
// System.out.println("min " + min );
}
}
@v-kavya
Copy link

v-kavya commented Jun 19, 2024

In java7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment