You are provided with 3 numbers : input1, input2 and input3.
Each of these are four digit numbers within the range >=1000 and <=9999.
i.e.
1000 <= input1 <= 9999
1000 <= input2 <= 9999
1000 <= input3 <= 9999
You are expected to find the Key using the below formula –
Key = (Hundreds digit of input1 x Tens digit of input2) – (Largest digit of input3)
For e..g. if input1 = 3521, input2=2452, input3=1352, then Key = (5 x 5) – 5 = 20
Assuming that the 3 numbers are passed to the given function, Complete the function to find and return the Key. Full java code
ANSWER: (You can use intellij)
package com.company; import java.util.Scanner; import java.util.Arrays; public class Main { public static void main(String[] args) { // write your code here int key1 =0; int key2 =0; int key33 = 0; int KEY; int[] key3 = new int[4]; Scanner girdi = new Scanner(System.in); System.out.println("Please write 1000 <= input1 <= 9999 "); int input1 = girdi.nextInt; System.out.println("Please write 1000 <= input2 <= 9999 "); int input2 = girdi.nextInt; System.out.println("Please write 1000 <= input3 <= 9999 "); int input3 = girdi.nextInt; while(input1 >= 1000) { input1 = input1 - 1000; input1 = input1; } while(input1 >= 100) { input1 = input1 - 100; key1 = key1 + 1; } while(input2 >= 100) { input2 = input2 - 100; input2 = input2; } while(input2 >= 10) { input2 = input2 - 10; key2 = key2 + 1; } key3[0]=input3/1000; input3=input3-(1000*key3[0]); key3[1]=input3/100; input3=input3-(100*key3[1]); key3[2]=input3/10; input3=input3-(10*key3[2]); key3[3]=input3; key33 = Arrays.stream(key3).max.getAsInt; KEY = (key1 * key2) - key33; System.out.println("Hundreds digit of input1 = " + key1); System.out.println("Tens digit of input2 = " + key2); System.out.println("Largest digit of input3 = " + key33); System.out.println("KEY = " + KEY); } }
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-min);
res.append(astr);
}
if(res.length()==0) return 0;
String ress = res.toString();
int r = Integer.parseInt(ress);
return r;
}