File tree 1 file changed +45
-0
lines changed
1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ package easy ;
2
+
3
+ /**
4
+ * Have the function LargestPair(num) take the num parameter being passed
5
+ * and determine the largest double-digit number within the whole number.
6
+ * ---
7
+ * For example: if num is 4759472 then your program should return 94 because
8
+ * that is the largest double-digit number.
9
+ * The input will always contain at least two positive digits.
10
+ */
11
+ public class LargestPair {
12
+
13
+ /**
14
+ * Largest pair function.
15
+ *
16
+ * @param num input number
17
+ * @return the largest double-digit number within the whole number
18
+ */
19
+ private static int largestPair (int num ) {
20
+ int largest = Integer .MIN_VALUE ;
21
+ String numstr = Integer .toString (num );
22
+ for (int i = 0 ; i < numstr .length () - 1 ; i ++) {
23
+ int i1 = Integer .parseInt (String .valueOf (numstr .charAt (i )));
24
+ int i2 = Integer .parseInt (String .valueOf (numstr .charAt (i + 1 )));
25
+ int pair = i1 * 10 + i2 ;
26
+ if (pair > largest ) {
27
+ largest = pair ;
28
+ }
29
+ }
30
+ return largest ;
31
+ }
32
+
33
+ /**
34
+ * Entry point.
35
+ *
36
+ * @param args command line arguments
37
+ */
38
+ public static void main (String [] args ) {
39
+ int result1 = largestPair (567353664 );
40
+ System .out .println (result1 );
41
+ int result2 = largestPair (8163264 );
42
+ System .out .println (result2 );
43
+ }
44
+
45
+ }
You can’t perform that action at this time.
0 commit comments