Question:
can u help me with my java programming subject?
Silhouette N
2008-12-04 03:42:11 UTC
can u help me whenever i need to ask a question about my java programming subject i really have to learn the language of it and u have to elaborate the specific details on java please

can u explain what's the use of import java.io.*;

and

BufferedReader kfdsj = new BufferedReader (new InputStreamReader(System.in));


please help me


i'll type the program so u can help me with it u have to explain the specific details of the program please........



import java.io.*;
public class distance{
public static void main (String [] args) throws Exception{
BufferedReader data = new BufferedReader (new InputStreamReader(System.in));

int kilo;
String x_kilo;
double distance = 0.61237;
double d = 0.61237;

System.out.println("input a number: ");
x_kilo = data.readLine( );
kilo = Integer.parseInt(x_kilo);
d = kilo*distance;
System.out.println("the kilo convert to distance is: "+ d);
}
}



PLEASE EXPLAIN IT NOT THE OUTPUT THE PROGRAM I'M POINTING EVERY THING THAT YOU CAN EXPLAIN ABOUT THE CODES
Four answers:
Saj
2008-12-04 05:14:39 UTC
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.
Andy T
2008-12-04 04:06:33 UTC
The first import java.io.*; is explicitly stating that the rest of the code might infer to classes under the particular name space under java.io.* so instead of refer by full name as java.io.BufferReader the program code can refer by its given name of BufferReader with the surname of java.io being implied and intelligently added by compiler. Namespacing has another true useful functionality that a Programming 101 student can ignore for a while.



BufferedReader data = new BufferedReader (new InputStreamReader(System.in)); is a bit harder to explain, Java's rather convoluted way of creating a fully useful input stream hinges on 2 reasonings: one: sometime down the road you might be concerned about efficiency of network streams or streams representing some other input method. two: Java's designers firmly believed that for APIs one class suppose to handle only one function, there are 3 functionalities required by your little program simply on the capturing of keyboard entry so there you have it, an object passed to a construction of another object that passed to the construction of yet another object that is the interest of your little program.
Kashyap Patel
2008-12-04 03:48:43 UTC
import java.io is included the java's input output operation classes .



BufferedReader data = new BufferedReader (new InputStreamReader(System.in));

is used to get string form command base. not command line.



this is the program for the conversion in to the kilimeter.
gaudioso
2016-10-02 14:02:37 UTC
basically having a fashion with the comparable signature (approach call and argument record) interior the subclass will override the tactic of the super type. in the adventure that your super type approach is termed open() then basically create a open() approach on your subclass.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...