The document discusses Java's primitive data types including their ranges and literal constants. It covers char, boolean, byte, short, int, long, float, and double data types. It also discusses variables, symbolic constants, and arithmetic operators.
24. Review Example 1 import java.io.*; class RestaurantBill { public static void main (String[] args) throws IOException { String charData; double basicCost; BufferedReader stdin = new BufferedReader ( new InputStreamReader( System.in ) ); System.out.println("Enter the basic cost:"); charData = stdin.readLine(); basicCost = Double.parseDouble( charData ) ; System.out.println("basic cost: " + basicCost + " total cost: " + (basicCost + basicCost*0.06 + basicCost*0.20)); } }
25. Review Example 2 import java.io.*; class SquareRoot { public static void main (String[] args) throws IOException { String charData; double value; // read in a double BufferedReader stdin = new BufferedReader (new InputStreamReader(System.in)); System.out.print ("Enter a double:"); charData = stdin.readLine(); value = Double.parseDouble( charData ) ; // calculate its square root double result = Math.sqrt( value ); // write out the result System.out.println("square root: " + result ); } }
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38. Example import java . io .* ; class CookieChecker { public static void main ( String [] args ) throws IOException { BufferedReader stdin = new BufferedReader ( new InputStreamReader ( System . in ) ) ; // get the number of cups of flour System . out . println (" How much flour do you have? ") ; String inData = stdin . readLine () ; int flour = Integer . parseInt ( inData ) ; // get the number of cups of sugar System . out . println (" How much sugar do you have? ") ; inData = stdin . readLine () ; int sugar = Integer . parseInt ( inData ) ; // check that there are enough of both ingredients if ( flour > = 4 && sugar > = 2 ) System . out . println (" Enough for cookies !" ) ; else System . out . println (" sorry ...." ) ; } }