package chapter.pkg4; import javax.swing.JOptionPane; import java.util.Scanner; public class Chapter4 { public static void main(String[] args) { long n = 1000000; //JOptionPane.showMessageDialog(null, n * n); byte small = 7; long result = n * n; //JOptionPane.showMessageDialog(null, result); double f = 4.35; //JOptionPane.showMessageDialog(null, 100 * f); double answer = f * 100; //if (answer == 435) {} double balance = 100; // no problem int balance2 = (int)13.9999; // problem //JOptionPane.showMessageDialog(null, balance2); final double NICKEL_VALUE = 0.05; int items = 1; items++; // increments by 1 items += 1; // same thing items--; // decrements by 1 items -= 1; // same thing // integer division JOptionPane.showMessageDialog(null, "7/4: " + 7/4); JOptionPane.showMessageDialog(null, "7.0/4: " + 7.0/4); JOptionPane.showMessageDialog(null, "(double)7/4: " + (double)7/4); //modular division JOptionPane.showMessageDialog(null, "7 % 4: " + 7 % 4); // powers and roots JOptionPane.showMessageDialog(null,Math.pow(3, 4)); JOptionPane.showMessageDialog(null,Math.sqrt(81)); JOptionPane.showMessageDialog(null,Math.floor(3.9)); JOptionPane.showMessageDialog(null,Math.round(3.9)); //JOptionPane.showMessageDialog(null,"Hello".length()); // concatenation String name = "Dave"; String msg = "Hello, " + name; JOptionPane.showMessageDialog(null,msg); String a = "Agent"; int n2 = 7; String bond = a + n2; JOptionPane.showMessageDialog(null,bond); // how to convert from STring to int String value = "19"; int m = Integer.parseInt(value); JOptionPane.showMessageDialog(null,m * m); String value2 = "3.14159"; double mm = Double.parseDouble(value2); JOptionPane.showMessageDialog(null,mm / 2); String today = "Happy Friday, Metuchen!"; String msg = today.substring(0, 7); JOptionPane.showMessageDialog(null, msg); msg = today.substring(7); JOptionPane.showMessageDialog(null, msg); Scanner in = new Scanner(System.in); System.out.println("How old are you? "); int age = in.nextInt(); } }