import java.util.Scanner;
public class Temperature {
public static void main (String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Enter a temperature in celsius: ");
double cTemp = in.nextInt();
double fTemp = cTemp * 9.0 / 5 + 32;
System.out.println(cTemp + " c = " + fTemp + " F");
System.out.printf("%.1f c = %.1f F", cTemp, fTemp);
}
}
import java.util.Scanner;
public class ConvertTime {
public static void main (String[] args) {
//CONSTANTS
final double SECONDS_IN_HOUR = 3600;
final double SECONDS_IN_MINUTE = 60;
//READ INPUT
Scanner in = new Scanner(System.in);
System.out.print("Enter an amount of seconds: ");
int originalSeconds = in.nextInt();
//TIME CALCULATE
int seconds = originalSeconds;
int hours = seconds / SECONDS_IN_HOUR; //How many hours are there?
seconds = seconds % SECONDS_IN_HOUR; //How many seconds are left over?
int minutes = seconds / SECONDS_IN_MINUTE; //How many minutes are there?
seconds = seconds % SECONDS_IN_MINUTE; //How many seconds are left over after that?
//OUTPUT
System.out.println(originalSeconds + " seconds = " + hours + " hours, " + minutes + " minutes, and " + seconds + " seconds.");
System.out.printf("%d seconds = %d hours, %d minutes, and %d seconds.", originalSeconds, hours, minutes, seconds);
}
}
import java.util.Scanner;
import java.util.Random;
public class GuessMyNumber {
public static void main (String[] args) {
// pick a random number
Random random = new Random();
int randomNumber = random.nextInt(100) + 1;
// Get input
System.out.println("I'm thinking of a number between 1 and 100");
System.out.println("(including both). Can you guess what it is?");
System.out.print("Type a number: ");
Scanner in = new Scanner(System.in);
int guess = in.nextInt();
// Output
System.out.println("Your guess is: " + guess);
System.out.println("The number I was thinking of is: " + randomNumber);
System.out.println("You were off by: " + (randomNumber - guess));
}
}