Getting the output

Im getting the wrong output of 1, the output should be 101. what is im doing wrong?

import java.util.*;
public class walt2
{
   
public static void main(String[] args)
{

int x=1, y=6, z=2;
int p =0,q=0,r=0;
if(x+y+z<=10)
p++;
else
q++;
r++;
System.out.println(p);

}
}
walt2.JPG
waltbaby315Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TomasPCommented:
You have set p to 0 and incremented it by 1 if(x+y+z<=10)
Since 9 is less than or equal to 10 then p will be incremented from zero to one and you are printing out p
Where would 101 come from?
0
Bryan ButlerCommented:
Sounds like you're trying to do binary addition with integers.  Is binary what you want?
0
waltbaby315Author Commented:
It's suppose to be the answer after the values of p,q and r is executed. I was  wondering how they came up with 101.
0
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

TomasPCommented:
It looks like part of the problem is missing. Even a binary dump doesn't come up with 101.  A binary dump of the total of x,y,z does result in binary 1001
You should put your conditional code in {} to make the logic clearer since you are new
did they mean....
if(x+y+z<=10) {
p++;
}
else {
q++;
}
r++;
0
waltbaby315Author Commented:
I put in thast solution and this is the error that I got.
walt21.JPG
0
TomasPCommented:
Please post the whole file. It looks like you have one too many {
0
waltbaby315Author Commented:
I put in thast solution and i still get  the output of 1

import java.util.*;
public class walt2
{
   
public static void main(String[] args)
{

int x=1, y=6, z=2;
int p =0,q=0,r=0;
if(x+y+z<=10) {
p++;
}
else {
q++;
}
r++;
System.out.println(p);

}
}
walt2.JPG
0
TomasPCommented:
Ok, that is what is expected. Can you post the problem proposed as stated. Per your original code, the answer is 1 and not 101
The only way I can see 101 as and answer is if you print
p,q, r out.
that would result in
101
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
waltbaby315Author Commented:
how would I print p,q,r. I tried System.out.println(p)(q)(r); and System.out.println(p,q,r); and they both came up with errors.

0
TomasPCommented:
you can try splitting it up
System.out.println(p);
System.out.println(q);
System.out.println(r);
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.