I am going to explain as simply I can. After every statement I included an explanation.
import java.io.*;
Explanation: import statements are for using pre-built classes and interfaces. Pre-built means those classes were written by SUN microsystem programmers or by some other programmers. It makes life easier. For example, you want to format a date which looks like 12012008 to 12/01/2008. In order to do that you can write a class or you can use the
date functionality that is given to you by java. All you gotta do is import the library that does it. In this case, you need to import: import java.text.SimpleDateFormat; import java.util.Date;
public class distance{
Explanation: A class usually represents an object. It's more like a template for an object. You define the object's properties inside the class. In this case, one of the properties of the object "distance" is the variable "data".
public static void main (String [] args) throws Exception{
Explanation: Every main class should have a main method. A main method usually gets executed first.
Main method takes arguments(String[] args).
BufferedReader data = new BufferedReader (new InputStreamReader(System.in));
Explanation: BufferedReader reads input. In this case it is reading from Keyboard. How do you know that? You know that because it used new InputStreamReader(System.in).
System.in indicates Keyboard input. If you want to read a file, you might wanna use:
BufferedReader reader = new BufferedReader(new FileReader(new File("file.txt")));
int kilo;
String x_kilo;
double distance = 0.61237;
double d = 0.61237;
Explanation: The 4 statements above are for declaring different type of object properties.
For example, int kilo will hold a whole number, not a text. String x_kilo will hold a text.
double distance could hold a fractional value like 0.61237.
System.out.println("input a number: ");
Explanation: This is writing a piece of string in the default screen.
x_kilo = data.readLine( );
Explanation: you are using data which is a BufefredReader to fetch input from keyboard. And then you are storing
the value that was fetched from the keyboard in x_kilo. You are storing it in x_kilo but not in kilo because
data.readLine() fetches text. Since x_kilo is a string, you can store it there. Users might enter text rather than
a number. You know users!
kilo = Integer.parseInt(x_kilo);
Explanation: In order to use the number which was fetched as text using data.readLine(), you need to store it in
an integer variable. Here it's parsing the text to be an integer and storing it in the integer variable which is kilo.
d = kilo*distance;
Explanation: simple computation which results in a fractional value. That's why it's getting stored in a double variable.
System.out.println("the kilo convert to distance is: "+ d);
Explanation: Same as other System.out.println statement above. This time, just a difefernt piece of string/text.
}
Explanation: Closing of main method
}
Explanation: Closing of the class
Hope this helps.