Search In
• More options...
Find results that contain...
Find results in...

no result of switch case

thanks dude

Share on other sites

why the freak of result is x?

Share on other sites

no freaking soldiers here?

Share on other sites

You're missing a break and it's also always recommended to have a default:

``` switch (ch) {
case 'a':  x = 1;
break;
case 'b':  x = 2;
break;
case 'c':  x = 3;
break;
//But what if 'ch' was not a, b  or c??
default: x = 0;
}
System.out.print("x now is: " + x);```

"We're all in this together, might as well be friends" Tom, Toonami.

mini eLiXiVy: my open source 65% mechanical PCB, a build log, PCB anatomy and discussing open source licenses: https://linustechtips.com/topic/1366493-elixivy-a-65-mechanical-keyboard-build-log-pcb-anatomy-and-how-i-open-sourced-this-project/

mini_cardboard: a 4% keyboard build log and how keyboards workhttps://linustechtips.com/topic/1328547-mini_cardboard-a-4-keyboard-build-log-and-how-keyboards-work/

Share on other sites

1 hour ago, Minibois said:

You're missing a break and it's also always recommended to have a default:

```
switch (ch) {
case 'a':  x = 1;
break;
case 'b':  x = 2;
break;
case 'c':  x = 3;
break;﻿
//But what if 'ch' was not a, b  or c??
default: x = 0;﻿
}
System.out.print("x now is: " + x);```

what is the function of 10+1?

Share on other sites

3 minutes ago, buklu said:

what is the function of 10+1?

the Math.random method normally provides you with a double variable (a number value that can hold decimals, int variables hold numbers without decimals. This is important info for later in this explanation).

This method will give you at least 0.0, at most will give you 0.9 (repeating 9's). By doing *10, you make it so instead of getting 0.15, you get 01.5. Of course this is placed into an int, so you are losing the decimal points. So at this point you get the numbers (pseudo)randomly: 0, 1, 2, [...], 8 or 9.

You do +1 so that instead of getting at least 0, you get at least 1. You also do that +1 so you get at most 10.

So with this method Java gives you a (pseudo)random number from this list: 1, 2, 3, 4, 5, 6, 7, 8, 9 or 10.

"We're all in this together, might as well be friends" Tom, Toonami.

mini eLiXiVy: my open source 65% mechanical PCB, a build log, PCB anatomy and discussing open source licenses: https://linustechtips.com/topic/1366493-elixivy-a-65-mechanical-keyboard-build-log-pcb-anatomy-and-how-i-open-sourced-this-project/

mini_cardboard: a 4% keyboard build log and how keyboards workhttps://linustechtips.com/topic/1328547-mini_cardboard-a-4-keyboard-build-log-and-how-keyboards-work/

Share on other sites

On 11/28/2018 at 8:57 PM, Minibois said:

the Math.random method normally provides you with a double variable (a number value that can hold decimals, int variables hold numbers without decimals. This is important info for later in this explanation).

This method will give you at least 0.0, at most will give you 0.9 (repeating 9's). By doing *10, you make it so instead of getting 0.15, you get 01.5. Of course this is placed into an int, so you are losing the decimal points. So at this point you get the numbers (pseudo)randomly: 0, 1, 2, [...], 8 or 9.

You do +1 so that instead of getting at least 0, you get at least 1. You also do that +1 so you get at most 10.

So with this method Java gives you a (pseudo)random number from this list: 1, 2, 3, 4, 5, 6, 7, 8, 9 or 10.

also,where should \n be placed on total surface area?thanks bro

Share on other sites

1 hour ago, buklu said:

also,where should \n be placed on total surface area?thanks bro

I don't understand your question. Using \n inside a String will give you an enter (next line). Is that what you are after?

"We're all in this together, might as well be friends" Tom, Toonami.

mini eLiXiVy: my open source 65% mechanical PCB, a build log, PCB anatomy and discussing open source licenses: https://linustechtips.com/topic/1366493-elixivy-a-65-mechanical-keyboard-build-log-pcb-anatomy-and-how-i-open-sourced-this-project/

mini_cardboard: a 4% keyboard build log and how keyboards workhttps://linustechtips.com/topic/1328547-mini_cardboard-a-4-keyboard-build-log-and-how-keyboards-work/

Share on other sites

9 hours ago, Minibois said:

I don't understand your question. Using \n inside a String will give you an enter (next line). Is that what you are after?

and also the error of %.2f,can you explain?

Share on other sites

7 hours ago, buklu said:

and also the error of %.2f,can you explain?

As far as I know you have to approach %.2f a little something like this:

`"Your results is: " + String.format("%.2f", numberYouUse);`

"We're all in this together, might as well be friends" Tom, Toonami.

mini eLiXiVy: my open source 65% mechanical PCB, a build log, PCB anatomy and discussing open source licenses: https://linustechtips.com/topic/1366493-elixivy-a-65-mechanical-keyboard-build-log-pcb-anatomy-and-how-i-open-sourced-this-project/

mini_cardboard: a 4% keyboard build log and how keyboards workhttps://linustechtips.com/topic/1328547-mini_cardboard-a-4-keyboard-build-log-and-how-keyboards-work/

Share on other sites

how to deal with it?