Created
September 21, 2024 10:05
-
-
Save vdeemann/79c141a9214cf8b0ee4fd225123e7038 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Puzzle4 { | |
public static void main(String [] args) { | |
Value [] values = new Value[6]; | |
int number = 1; | |
int i = 0; | |
while (i < 6) { | |
values[i] = new Value(); | |
// 0-1 1-10 2-100 3-1000 4-10000 5-100000 6- | |
values[i].intValue = number; | |
// 0-10 1-100 2-1000 3-10000 4-100000 5-1000000 6- | |
number = number * 10; | |
i = i + 1; | |
} | |
int result = 0; | |
i = 6; | |
while (i > 0) { | |
i = i - 1; | |
// 0-543345 1-543340 2-543300 3-543000 4-540000 5-500000 6- | |
result = result + values[i].doStuff(i); | |
} | |
System.out.println("result " + result); | |
} | |
} | |
class Value{ | |
int intValue; | |
public int doStuff(int factor) { | |
if (intValue > 100) { | |
return intValue * factor; | |
} else { | |
return intValue * (5 - factor); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment