Contents
- ./Float.java
- ./Hello.java
- ./TestScore.java
./Float.java 1/3
[top][prev][next]
/**
* This class demonstrates how to specify floats vs doubles in Java.
*
* But, it's easier to just use doubles.
*
* @author Sara Sprenkle
*/
public class Float {
/**
* Called when user runs
* java Float
*/
public static void main(String[] args) {
float f = 3.14;
// double f = 3.14;
System.out.println(f);
}
}
./Hello.java 2/3
[top][prev][next]
/**
* Our first Java class
*
* All code in a Java program must belong to a class.
* There is typically one class per file, and the file name is ClassName.java
* Compile this code using
* javac Hello.java
* Run the compiled bytecode Hello.class using
* java Hello
*
* @author Sara Sprenkle
*/
public class Hello { //File must be saved as Hello.java
/**
* Called when user runs
* java Hello
*/
public static void main(String[] args) { // Blocks start/end with {}
System.out.println("Hello!"); // Lines end with ;
}
}
./TestScore.java 3/3
[top][prev][next]
/**
* Demonstrate automatically changing a double to a String in a print statement
* and casting a variable to a certain type.
*
* @author Sara Sprenkle
*/
public class TestScore {
public static void main(String[] args) {
int totalPoints = 110;
int earnedPoints = 87;
/* try removing the (double) below to see what happens. */
double testScore = (double) earnedPoints/totalPoints;
System.out.println("Your score is " + testScore);
}
}
Generated by GNU Enscript 1.6.5.90.