Created
February 27, 2019 01:50
-
-
Save jaohaohsuan/aee05a524a9aa06fe5280f67f2835c58 to your computer and use it in GitHub Desktop.
comp601 week 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package comp601.week2; | |
import static java.lang.System.out; | |
import java.util.Scanner; | |
public class Main { | |
private static Scanner input = new Scanner(System.in); | |
public static void main(String[] args) { | |
// TODO Auto-generated method stub | |
//readString(); | |
//readInteger(); | |
readDouble(); | |
input.close(); | |
} | |
public static void readString() { | |
out.print("May I have your name? "); | |
out.printf("Hello, %s\n", input.nextLine()); | |
} | |
public static void readInteger( ) { | |
out.print("Please enter a square side length: "); | |
int sideLength = input.nextInt(); | |
int square = sideLength * sideLength; | |
out.printf("The sqaure area is %d.\n", square); | |
} | |
public static void readDouble() { | |
out.print("Please enter a cube side length: "); | |
double sideLength = input.nextDouble(); | |
//double cube = sideLength * sideLength * sideLength; | |
double cube = Math.pow(sideLength, 3); | |
out.printf("The cube size is %.2f.\n", cube); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment