# 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
###### Who is Participating?

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.

Commented:
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
Commented:
Sounds like you're trying to do binary addition with integers.  Is binary what you want?
0
Author 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
Commented:
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
Author Commented:
I put in thast solution and this is the error that I got.
walt21.JPG
0
Commented:
Please post the whole file. It looks like you have one too many {
0
Author 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
Commented:
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

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

Author 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
Commented:
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.