[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]

i just started java and i was wondering, if I wanted to negate

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: 11
Thread images: 1

File: ss (2015-12-18 at 07.15.12).png (931KB, 1241x753px) Image search: [Google]
ss (2015-12-18 at 07.15.12).png
931KB, 1241x753px
i just started java and i was wondering, if I wanted to negate this

index =0;
int[]array = new int[10];
while((!salaries==-1) && index<salaries.length){


I want to let up to 10 users enter their salaries, and exit the loop using -1. would this work? is my exclamation mark used correctly? ty O_O
>>
>>16580708
Yes lol for sure. If you wanted to negate what?

Anyway. Why would you want to exit with -1?
>>
>>16580724
I'll have the user enter into salary, and they can enter -1 to exit the loop.

also i think it should be while(!salaries[index]==-1)
>>
while (index < 10) {
// read salary
index++;
}
>>
>>16580732
well, I want it to also let the user leave the loop when they want, by entering -1. so I want the while loop to only work when the user has not entered -1 for salaries[index]. I just wanted to know if I placed my exclamation point properly.
>>
>>16580731
You could use an variable to store the users input and if that input is equal to -1 the exit the program. Also, have count variable that starts at one and increments until it reaches 10. Include that in your check to see if you want to exit or not. So, you'll exit your program if the input equals -1 or if your count is greater or equal to 10 (as they've reached the maximum number of allowed inputs)
>>
>>16580732

Inside the loop

if( salaryInput == -1){
break;
}
>>
>>16580742
Or I could do boolean exitVar = false,

while(exitVar==false &&index<salaries[index].length){
if (salaries[index]==-1){
exitVar=true;
}
salaries[index] = enter name

if (salaries[index]==""){
print error
}else{
index++
}
}

Does this work? wanted to do it without break.
>>
>>16580708
>!salaries==-1
What the fuck?

>>16580731
>also i think it should be while(!salaries[index]==-1)
! gives you a boolean, not int. Use !=

salaries[index] != -1
>>
>>16580772
thanks
>>
>>16580754
index=0;
while(index < 10)
{
//get input
if(input == -1)
System.exit(0);
salaries[index] = input;
index++;
}
Thread posts: 11
Thread images: 1


[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.