[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Retarded question here, I'm learning java and was trying
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

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

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

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.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.