Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


mehul jain
class distance
1 Answer(s)      3 years and 6 months ago
Posted in : Java Beginners


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.


Advertisement
View Answers

January 18, 2011 at 11:24 AM


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



Related Tutorials/Questions & Answers:
class distance
class distance  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
Edit Distance
Edit Distance  I want java programming ask from user input two string and the program find the edit distance between two strings and find table and optimal solution using GUI
Advertisements
Distance conversion - Java Beginners
Distance conversion  Write an application that reads a distance... the distance to kilometres, feet and inches, according to the user?s selection...() for the user selection. ? Write a method to read a distance in metres from
Delhi to Udaipur by road distance
Delhi to Udaipur by road distance  delhi to udaipur by road distance
Another distance conversion - Java Beginners
Another distance conversion  Write an application that reads a distance in metres. The program will then convert the distance to kilometres, feet... = 1640.5 feet 500 * 39.37 = 19685 inches   import java.io.*; public class
Distance in meters - Java Beginners
Distance in meters  Write a program that asks the user to enter a distance in meters. The program will then present the following menu of selections... the program The program will convert the distance to kilometers, inches
Hill stations near Delhi distance
Hill stations near Delhi distance   Hi, Can any one tell the distances of the Hill stations near Delhi? Thanks
Road distance using Java - Java Beginners
Road distance using Java  Dear All i am calculating the straight line distance between two latlong points using the simple mathematical formula but i need the Real Road Driving Distance // protected double distance(double pX
Distance learning business management
Distance learning business management courses are on high demand today... nature is regular or class courses and don't suit for a working professional. But those students should not worry as many institutions have started distance
GUI and how to convert a distance - Java Beginners
application that can be is used to convert a distance unit in miles into its... java.awt.event.*; import java.util.regex.*; import java.text.*; class ConvertMile...=new JTextField(20); t5=new JTextField(20); l1=new JLabel("Enter distance
loop to input multiple points to calculate final distance and speed
loop to input multiple points to calculate final distance and speed  import java.util.Scanner; public class Travel { private double time; private double distance; public Travel() { time=0; distance=0
Hill Stations near Delhi distance
Distance of Major Hill Stations From Delhi  In this page we have listed all the Hill Stations near Delhi with their distance from central Delhi... and northeastern India. List of Hill Stations near Delhi with distance Sr
VoIP Long Distance
VoIP Long Distance          VoIP Designing a Long-Distance Network The long-distance Voice over IP (VoIP) network solution is a set of network design
How can i display the distance of a line drawing randomly?
How can i display the distance of a line drawing randomly?  How can i display the distance of a line drawing randomly
class
class  Is a class a subclass of itself
class
is a class to represent a country in medal tally. It has an attribute of country... medals. In this class, you should also define constructors, and assessor, mutator methods. Task 2 MedalTally.java is a class to model a medal tally, containing
Class
Class, Object and Methods       Class : Whatever we can see in this world all the things... is termed as a class. All the objects are direct interacted with its class
Super class of an Exception class
Super class of an Exception class  hello,,, What is super class of an Exception class?   hii,, the super class of an exception is throwable class. and the super class of an throwable class is the object class
Class
Class       This section explores the concept of a class in reference to object oriented programming techniques. A class defines the properties of  objects and methods used
Explain final class, abstract class and super class.
Explain final class, abstract class and super class.  Explain final class, abstract class and super class.   Explain final class, abstract class and super class. A final class cannot be extended. A final class
class file
class file  How to create class file in jsf easily
class loaders
class loaders   Explain static and dynamic class loaders
.class and .tld
.class and .tld  how to create .class and .tld file
inner class
inner class  what is mean by inner class   Inner class is a non-static class which is defined inside another class
Node class
Node class   hii, What is a node class?   hello, A node class is a class that has added new services or functionality beyond the services inherited from its base class
Matrix Class
Matrix Class   A class to manage matrices and add them. Create in the driver class two objects of it and use the add method
Matrix Class
Matrix Class   A class to manage matrices and add them. Create in the driver class two objects of it and use the add method
wrapper class
wrapper class  list wrapper class methods
wrapper class
wrapper class  wrapper class methods
printstrim class
printstrim class  discribe PrintStream class
printstrim class
printstrim class  discribe PrintStream class
Abstract class
Abstract class  what is an Abstract class
Abstract class
Abstract class  Can an abstract class be final
singleton class
singleton class  What is singleton class
Locale class
Locale class  What is the Locale class
immutable class
immutable class  How to make a class immutable
Java class
Java class  What is the purpose of the Runtime class
lock on a class
lock on a class  hello, Can a lock be acquired on a class?   hiii,, Yes, a lock can be acquired on a class. This lock is acquired on the class's Class object
objective c extending a class with a class
objective c extending a class with a class  I need an example for extending a class with a class in objective c. thanks
objective c extending a class with a class
objective c extending a class with a class  I need an example for extending a class with a class in objective c. thanks
Nested class
Nested class  What is nested class?  when a class is defined within another class then such a class is called a nested class. Nested... readable and maintainable code. class OuterClass { ... static class
robot class
robot class  please send me uses of robot class and some examples using robot class
wrapper class
wrapper class  why wrapper class does not have a default constructor
java.sql.DriverManager class
java.sql.DriverManager class  Why isn't the java.sql.DriverManager class being found
super class
super class  which is the super base class in java
create a class
create a class  plz provide any example related to class
class file
class file  how to convert java classfile into java sourcefile
Adapter Class
Adapter Class  Hello Everybody, Can anybody help me to describe what is Adapter class and when to use this class and give a suitable example... visit the following links: What is Adapter Class Example of Adapter Class
abstract class
abstract class  Can there be an abstract class with no abstract methods
Wrapper Class
Wrapper Class  what is wrapper class in java and why we use it   Hi Friend, Wrapper class is a wrapper around a primitive data type. It represents primitive data types in their corresponding class instances e.g.
 

 

 

DMCA.com