Click here to Skip to main content
15,905,508 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
import java.io.*;
class Complex
{
	int a, b;
	BufferedReader br;
	void accept()
	{
		br = new BufferedReader (new InputStreamReader(System.in));
		try
		{
			System.out.println("Enter two numbers");
			int a= Integer.parseInt(br.readLine());
			int b= Integer.parseInt(br.readLine());
		}
		catch (IOException ioe)
		{
		}
	}
	void display()
	{
		System.out.println("Number 1 = " + a);
		System.out.println("Number 2 = " + b);
	
	
	}
	void add(Complex c1 , Complex c2)
	{
		a=c1.a+c2.a;
		b=c1.a+c2.a;
	}
	public static void main(String [] args)
	{
		Complex c1 = new Complex();
		Complex res = new Complex();
		Complex c2 = new Complex();
		c1.accept();
		c2.accept();
		res.add(c1,c2);
		res.display();

	}
		

}

This code is getting compiled and its running. But the output is not desired .
The addition of the 2 numbers is not getting printed.
when i call res.display the contents which is getting printed is
hour=0
minutes=0
seconds=0
Can anyone tell me why?

What I have tried:

Please help me resolve this.
Thanks
Posted
Updated 30-May-17 2:18am

1 solution

Yes, because you never set any values for a and b in your objects, you just set local values in the accept method.

And you are not going to learn Java by posting questions here for every basic mistake you make. I suggest you go to The Java™ Tutorials[^] and learn it in a properly structured way.
 
Share this answer
 
v2
Comments
palak22 30-May-17 9:18am    
Thanku. I will go through the java tutorial but for now can u help me by sending me the correct code.
If you do so it would be great help for me.
Thanks
Richard MacCutchan 30-May-17 11:50am    
Just remove the int declarations in your int a= Integer.parseInt(br.readLine()); statements.
Maciej Los 30-May-17 13:36pm    
5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900