
class distance-integer data member km1,km2,km3,m1,m2,m3. run()-to input the two distance and add them in the third. display()-to display the total distance. display the constructor if required.

Hi Friend,
Try this:
import java.util.*;
class distance
{
int km1,km2,km3;
public void run(){
Scanner input=new Scanner(System.in);
System.out.print("Enter km1: ");
km1=input.nextInt();
System.out.print("Enter km2: ");
km2=input.nextInt();
km3=km1+km2;
}
public void display(){
System.out.println("Total distance is: "+km3);
}
public static void main(String[] args)
{
distance d=new distance();
d.run();
d.display();
}
}
Thanks
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.