Created
November 21, 2017 13:55
-
-
Save alien3d/d5f6f062868dacece7b81de9f36632f2 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
package com.company; | |
/** | |
* Dummy Games.. But why seem same like c# yeah.. | |
* Rulez: | |
* 1) You SHALL NOT declare any additional using directives other than "using System". | |
* Yes.. | |
* 2) You are allowed to using the string class related functions, like: insert(), | |
* appened, trim()and etc for the implementation | |
* / not sure what is insert,append anyway.. i prefer base function like math,system,string,string builder | |
* 3) You SHALL NOT invoke the other .NET specific libraries to perform the conversion except rule 2. | |
* // Use system only | |
* 4) Your code style is graded, hence it is encouraged to structure the code professionally | |
* and equipped with relevant comments. | |
* Yeah dummy comment is availble | |
* 5) Usage of helper functions are encouraged. | |
* Not sure what is concept of helper .. I know javasript people use that word only | |
* <p> | |
* All | |
*/ | |
public class Main { | |
public static void main(String[] args) { | |
// write your code here | |
System.out.println("Pretty long time no play java anyway"); | |
// So now we create a method contain the interview.. | |
// what if return an empty string if value is negative. | |
System.out.println(" Answer MyIntToString(254, 16) return \"empty string\" : " + MyIntToString(-9, 16) + "\n"); | |
System.out.println(" Answer MyIntToString(254, 16) return \"FE\" : " + MyIntToString(254, 16) + "\n"); | |
System.out.println(" Answer MyIntToString(254, 8) return \"376\" : " + MyIntToString(254, 8) + "\n"); | |
System.out.println(" Answer MyIntToString(254, 2) return \"11111110\" : " + MyIntToString(254, 2) + "\n"); | |
} | |
public static String MyIntToString(int value, int numbase) { | |
String interview; | |
switch (numbase) { | |
case 16: | |
int remainderHex; | |
String resultHex = " "; | |
int zHex = value; | |
while (zHex > 0) { | |
remainderHex = zHex % 16; // module.. Can be divided till last drop i mean even number | |
zHex /= 16; // lazy zHex = Zhex /16 | |
resultHex = GetHexString(remainderHex) + resultHex; | |
} | |
interview = resultHex; | |
break; | |
case 8: | |
int remainderOc; | |
String resultOc = " "; | |
int xOc = value; | |
while (xOc > 0) { | |
remainderOc = xOc % 8; | |
xOc /= 8; | |
resultOc = Integer.toString(remainderOc) + resultOc; | |
} | |
interview = resultOc; | |
break; | |
case 2: | |
int remainderBin; | |
String resultBin = " "; | |
int xBin = value; | |
while (xBin > 0) { | |
remainderBin = xBin % 2; | |
xBin /= 2; | |
resultBin = Integer.toString(remainderBin) + resultBin; | |
} | |
interview = resultBin; | |
break; | |
default: | |
interview = "Not in interview request don't make a joke yeah"; | |
break; | |
} | |
return interview; | |
} | |
public static String GetHexString(int zz) { | |
String returnValue = " "; | |
switch (zz) { | |
case 1: | |
returnValue = Integer.toString(1); | |
break; | |
case 2: | |
returnValue = Integer.toString(2); | |
break; | |
case 3: | |
returnValue = Integer.toString(3); | |
break; | |
case 4: | |
returnValue = Integer.toString(4); | |
break; | |
case 5: | |
returnValue = Integer.toString(5); | |
break; | |
case 6: | |
returnValue = Integer.toString(6); | |
break; | |
case 7: | |
returnValue = Integer.toString(7); | |
break; | |
case 8: | |
returnValue = Integer.toString(8); | |
break; | |
case 9: | |
returnValue = Integer.toString(9); | |
break; | |
case 10: | |
returnValue = ("A"); | |
break; | |
case 11: | |
returnValue = ("B"); | |
break; | |
case 12: | |
returnValue = ("C"); | |
break; | |
case 13: | |
returnValue = ("D"); | |
break; | |
case 14: | |
returnValue = ("E"); | |
break; | |
case 15: | |
returnValue = ("F"); | |
break; | |
} | |
return returnValue; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment