Download presentation
Presentation is loading. Please wait.
1
Compiling and Running a Java Program
1) Compile the program to generate the bytecode (executable -- .class) using javac : > javac TempConverter.java 2) Interpret (run) the bytecode (executable .class) using the java interpreter: > java TempConverter Use an editor to type in the new Java program below. Note that the program name is TempConverter, so, by the naming rules of Java, your file name must be TempConverter.java. The class name must be the same filename. Start your editor (i.e. pico in UNIX or Notepad on your PC or NetBeans) : Save the file as TempConverter.java
2
import java.util.Scanner;
public class TempConverter { public static void main (String[] args) final int BASE = 32; final double CONVERSION_FACTOR = 5.0 / 9.0; double celsiusTemp, fahrenheitTemp; Scanner scan = new Scanner(System.in); System.out.print ("Enter a Fahrenheit temperature: "); fahrenheitTemp = scan.nextDouble(); celsiusTemp = CONVERSION_FACTOR * (fahrenheitTemp - BASE); System.out.println ("Celsius Equivalent: " + celsiusTemp); } Compile and run the code using the java compiler and interpreter commands.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.