• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why not working System.out.println(c=a+b);

 
Ritesh raushan
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why not working System.out.println(c=a+b);
 
fred rosenberger
lowercase baba
Bartender
Posts: 12123
30
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ritesh raushan wrote:why not working System.out.println(c=a+b);

I guarantee you that the above line works. However, I would bet that it is not doing what you think it should, so unless you tell us what you think it should do, we can't help.

My GUESS - and this is nothing more than a guess - is that you meant to write



but I can't be sure. That may not work, since I don't know what types a, b, and c are. I could be completely wrong.
 
Heshan Fernando
Greenhorn
Posts: 2
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that You may want to print "c=a+b" as a text,,,,,For that You have to make command this way,,,
System.out.println("c=a+b");

In this command,compiler get "c=a+b" as string data type and print c=a+b

otherwise if you want to print result of two numbers,,,you may have to assign values for a & b,,,and your source code should be this way,,,,
int a,b,c;
a=100;
b=200;
c=a+b;
System.out.println(c);
 
Ritesh raushan
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry it's working stranger type when i execute this code
my code asks from user but i have not write this type of code

output-enter two intgrs
12 34
46
do you want to continue(yes/n)
y//here if we write y or n code terminate

D:\sum>java Sum

this is my code

 
Campbell Ritchie
Sheriff
Pie
Posts: 48938
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That post doesn’t make sense. Do you want it to print the continuing question or not? Does it print the continuing question or not?
One way to get the continuing question is to use a do-while loop.
System.out.println(a + b); is probably preferable; the variable c is redundant in this instance.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ritesh raushan wrote:sorry it's working stranger type when i execute this code
my code asks from user but i have not write this type of code


One of two things is happening:

1. You have a different class called Sum and your classpath is set so that it's picking up that class before the one you posted.

2. Your Sum class used to be written to do what you're seeing. You changed it, but you forgot to recompile.
 
Ritesh raushan
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks jeff i got it Classpath problem.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome. Glad you got it sorted out.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic