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

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]
Please support this website by donating Bitcoins to 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
If a post contains copyrighted or illegal content, please click on that post's [Report] button and fill out a post removal request
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 4Archive shows an archive of their content. If you need information for a Poster - contact them.