Java tutorial - how to use Nested If's and switch cases

preview_player
Показать описание
This short little tutorial shows you how a nested if and a switch perform the same functions.
Рекомендации по теме
Комментарии
Автор

Thanks, Taylor, thanks for teaching me and showing me how to type it, too. Now I understand why a "Switch" is supposed to be a more efficient type format than yet another If-then-else block.

peterjerz
Автор

pretty nice, i hope your other videos are as good as this one, if they are i would like to subscribe twice.

UltraAnalisis
Автор

there is wrong in the switch !!
you didn't used the break after every case !
and thank you ^^

Rafa-igps
Автор

Yes, Daddy and I added "break;" after each "case", and it worked!

peterjerz
Автор

can we use a condition in switch case? like

switch(i){
case i>85 : System.out.println("A grade");
break;
case i>65 : System.out.println("b grade");
break;
case i>55 : System.out.println("c grade");
break;
case i>36: System.out.println("d grade");
break;
default : System.out.println("fail");

}

KOTHAABHISHEK
Автор

arent you supposed to use a{ break; ] after each switch statement???

cursedburny
Автор

Hi if you could please help me with my minor problem that would be great.

I have 6 Jtextfields that users are suppose to fill in.

I want a if statement for every field to check if the answer is correct.The first if statement works, But as soon as I add a second if statement in my Jbutton source it doesnt work.

Here is my code so far:

int TotalCorrect = 0;

int Answer1 =1;
int Answer2 =2;
int Answer3 =3;
int Answer4 =4;
int Answer5 =5;
int Answer6 =6;


int ConvertedAnswer1 =

//This works
if (ConvertedAnswer1 == Answer1)
{

TotalCorrect = + 1;

}
else
{

TotalCorrect = +0;

}


//Not working
if (ConvertedAnswer2 == Answer2)
{

TotalCorrect = + 1;

}
else
{

TotalCorrect = +0;

}



String FinMark =
txfOutput.setText(FinMark);

MarcusMeyerTricks
join shbcf.ru