Retarded question here, I'm learning java and was trying to make a program that reads numbers with letters, like 1k = 1000, is there a better way to write this exception than using try-catch?
Go to >>>/g/sqt
>>52537791
Iterate through all characters making replacements when needed.
Then cast to int.
>>52537791
int k = 000;
>>52537833
Heh..
OP here, will this work?
public static int getNumber(char uppercaseLetter) {
if (letter='K') {
return 000;
}
>>52537907
OP here, I tried doing it with else if, and it went something like this after the first thing I tried above ended up a fuck up:
int currentValue1;//new variable
input1 = input.nextLine();
if("A1".equals(input1)){
currentValue = 100;
}else if("A2".equals(input1)){
//do another case
}else if("B1".equals(input1)){
//do another case
}
int currentValue2;//new variable
input2 = input.nextLine();
if("A1".equals(input2)){
currentValue2 = 100;
}else if("A2".equals(input2)){
//do another case
}else if("B1".equals(input2)){
//do another case
}
Isn't there a better way people?
>>52538102
What. Just store the input to string. Use the String API for finding the characters and replacing it to appropriate values. Then convert the final value to int
>>52538133
Damn.
>>52538133
You mean something like this boss?
public static void main(String args[]) {
long[] numbers = new long[]{1000, 5821, 10500, 101800, 2000000, 7800000, 92150000, 123200000, 9999999};
for(long n : numbers) {
System.out.println(n + " => " + coolFormat(n, 0));
}
}
private static char[] c = new char[]{'k', 'm', 'b', 't'};
private static String coolFormat(double n, int iteration) {
double d = ((long) n / 100) / 10.0;
boolean isRound = (d * 10) %10 == 0;
I did it, disregard this thread.
>is there a better way to write this exception than using try-catch?
Nigger what the fuck are you doing
>>52538415
>using static methods for no reasons
are you trying to slow down your shit anon?