Sometimes is it necessary to create a method that converts numbers. This is the way to convert numbers in Java/Eclipse.
package P;
import java.io.PrintStream;
import java.util.Scanner;
public class C {
static final double GB_IN_MB = 1000;
PrintStream out;
Scanner in;
C() {
out = new PrintStream(System.out);
in = new Scanner(System.in);
}
void start() {
out.printf("Enter the number of GB(s): ");
double numberOfGBs = in.nextDouble();
in.close();
double numberOfMBs = numberOfGBs * GB_IN_MB;
out.printf("%f GB equals %f MB\n", numberOfGBs, numberOfMBs);
}
public static void main(String[] args) {
new C().start();
}
}
Explanation:
- create a package
- create a class
- import the PrintStream and Scanner class.
- Set theĀ constant: GB_IN_MB = 1000;
- Ask for input
- Calculate the output
- Finally, print the output
If you want to go back to the instruction to convert from hours to hours;minutes;seconds, click here.