[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Retarded question here, I'm learning java and was trying

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 12
Thread images: 2

File: ok.png (252KB, 662x785px) Image search: [Google]
ok.png
252KB, 662x785px
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.
>>
File: Troll_face.png (44KB, 1110x778px) Image search: [Google]
Troll_face.png
44KB, 1110x778px
>>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?
Thread posts: 12
Thread images: 2


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.