double price = 4.35 int pennies = (int)(4.35 * 100);
turn Gray
public void turnGray() { int gray = 0.2126 * red + 0.7152 * green + 0.0722 * blue; }
Math.pow(10, 3) Math.sqrt(4) Math.abs(3- 5) Math.min(300, 255) Math.max(0, -1)
math function
red = Math.min(255, red + 25);
import java.util.Scanner; public class InputDemo { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("How old ar you? "); int age = in.nextInt(); System.out.print("Next year, you will be "); System.out.println(age + 1); System.out.print("What is your weight? "); double.weight = in.nextDouble(); System.out.print("I hope next year that'll be "); System.out.print(weight * 0.95); } }
int cookiesPerDay; double cerealBoxesPerDay; String name; System.out.printf("%6d", cookiesPerDay); System.out.printf("%4.2f", cerealBoxesPerDay); System.out.printf("%s", name);
String name = "whitehouse"; name.length() name.substring(3, 7) name.indexOf("c") "Hello" + name
secret government elevator
import java.util.Scanner; public class ElevatorDemo { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Floor: "); int floor = in.nextInt(); int actualFloor; if (floor > 14) { actualFloor = floor - 2; } else { actualFloor = floor; } System.out.println("Actual floor: " + actualFloor); } }