You are provided with 3 numbers : input1, input2 and input3. Each of these are four digit numbers within the range >=1000 and <=9999 j.e. 1000 <= input1 <= 9999 1000 <= input2 <= 9999 1000 <= input3 <= 9999 You are expected to find the Key using the below formula - Key = [largest digit in the thousands place of all three numbers] [largest digit in the hundreds place of all three numbers] [largest digit in the tens place of all three numbers] [largest digit in the units place of all three numbers] For e..g. if input1 = 3521. input2=2452. input3=1352, then Key = [3] [5] [5] [2] = 3552
Answers
Answer:
For my Intro CS class we have to create a program that finds a certain number, in this case, an address. The address falls within 1000 and 9999 and has to meet the following criteria:
All four digits are different
The digit in the thousands place is three times the digit in the tens place
The number is odd
The sum of the digits is 27
So far, I've been able to generate the range of numbers and narrow out the odd ones,
Answer:
Explanation:
public class Main
{
public static int check(int input1,int input2,int input3)
{
String s1 = Integer.toString(input1);
int[] c1 = new int[s1.length()];
for (int i = 0; i < s1.length(); i++)
{
c1[i] = s1.charAt(i) - '0';
}
String s2 = Integer.toString(input2);
int[] c2 = new int[s2.length()];
for (int i = 0; i < s2.length(); i++)
{
c2[i] = s2.charAt(i) - '0';
}
String s3 = Integer.toString(input3);
int[] c3 = new int[s3.length()];
for (int i = 0; i < s3.length(); i++)
{
c3[i] = s3.charAt(i) - '0';
}
StringBuilder res = new StringBuilder("");
for(int i=0;i<s1.length();i++)
{
int mx= Math.max(c1[i],c2[i]);
int max = Math.max(mx,c3[i]);
// int mi= Math.min(c1[i],c2[i]);
// int min = Math.min(mi,c3[i]);
Integer astr = new Integer(max);
res.append(astr);
}
if(res.length()==0) return 0;
String ress = res.toString();
int r = Integer.parseInt(ress);
return r;
}
public static void main(String[] args) {
int res = check(3521,2452,1352);
System.out.println(res);
}
}