Distance Constractor without Paramaters
CONSTRACTOR:
public class Distance {
double zmk;
Distance(){
zmk=0.62137;
}
MAIN CLASS:
import java.util.Scanner;
public class Distance1 {
public static void main (String[]args){
Distance p1=new Distance();
Scanner distanceconverter = new Scanner(System.in);
System.out.println("Enter number in kilometer.");
double dis=distanceconverter.nextInt();
double miles=dis*p1.zmk;
System.out.println("Miles: "+miles);
}
}
No comments:
Post a Comment