Advertisement
zainarfi00

Chapter 3 Exercises

Oct 13th, 2015
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.03 KB | None | 0 0
  1. Chapter 3 Exercises
  2. PG 190 Number 6
  3. public class Pg180_6
  4. {
  5. public static void main(String[] args)
  6. {
  7. int x= Calculate(4,-5);
  8. System.out.println(x);
  9. }
  10. public static int Calculate(int x, int y)
  11. {
  12. return(Math.abs(Math.max(x,y)));
  13. }
  14. }
  15.  
  16. Pg 190 Number 8
  17. public class Pg190_8
  18. {
  19. public static void main(String[] args)
  20. {
  21. int a = 1;
  22. int b = 3;
  23. int c = 2;
  24. double xvertex=-(b/(2*a));
  25. double discr = discrim(a,b,c)/2*a;
  26. double x1 = xvertex+discr;
  27. double x2 = xvertex-discr;
  28. System.out.println(x1);
  29. System.out.println(x2);
  30. }
  31. public static double discrim(int a, int b, int c)
  32. {
  33. return(Math.sqrt(b*b-4*a*c));
  34. }
  35. }
  36.  
  37. Pg 190 Number 10
  38. public class Pg190_10
  39. {
  40. public static void main(String[] args)
  41. {
  42. double radius = 2.0;
  43. double area = Calculate(radius);
  44. System.out.println("area =" + area );
  45. }
  46. public static double Calculate(double x)
  47. {
  48. return(Math.PI*(x*x));
  49. }
  50. }
  51.  
  52. Pg 190 Number 12
  53. public class Pg190_12
  54. {
  55. public static void main(String[] args)
  56. {
  57. double a = 6.23;
  58. double b = 5;
  59. double notation = Calculate(a, b);
  60. System.out.println("Scientific Notation form of the number is " + notation);
  61. }
  62. public static double Calculate(double a, double b)
  63. {
  64. return(a*(Math.pow(10,b)));
  65. }
  66. }
  67.  
  68. Pg 191 Number 14
  69.  
  70. public class Pg191_14
  71. {
  72. public static void main(String[] args)
  73. {
  74. double radius = 3.0;
  75. double height = 4.5;
  76. double surfacearea = cylinderSurfaceArea(radius, height);
  77. System.out.println("The Surface Area of the Cylinder is " + surfacearea);
  78. }
  79. public static double cylinderSurfaceArea(double r, double h)
  80. {
  81. return((2*(Math.PI * (r*r))) + (2*r*h*Math.PI));
  82. }
  83. }
  84.  
  85. Pg 191 Number 16
  86.  
  87. public class Pg191_16
  88. {
  89. public static void main(String[] args)
  90. {
  91. double sideA = 8;
  92. double sideB = 5.2;
  93. double sideC = 7.1;
  94. double area = triangleArea(sideA, sideB, sideC);
  95. System.out.println("The area of the triangle is " + area);
  96. }
  97. public static double triangleArea(double a, double b, double c)
  98. {
  99. double s = (a + b + c)/2;
  100. return(Math.sqrt(s*(s - a)*(s - b)*(s - c)));
  101. }
  102. }
  103.  
  104. Pg 191 Number 18
  105.  
  106. import java.util.*;
  107. public class Pg191_18
  108. {
  109. public static void main(String[] args)
  110. {
  111. String str1 = "hey now";
  112. for(int i; i <= str1.length(); i++)
  113. {
  114. System.out.println(str1.charAt(i+1));
  115. }
  116. }
  117. }
  118.  
  119. Pg 191 Number 20
  120.  
  121. import java.util.*;
  122. public class Pg191_20
  123. {
  124. public static void main(String[] args)
  125. {
  126. Scanner console = new Scanner(System.in);
  127. System.out.println("On what day of the month were you born?");
  128. int day = console.nextInt();
  129. System.out.println("What is the name of the month in which you were born?");
  130. String month = console.next();
  131. System.out.println("During what year were you born?");
  132. int year = console.nextInt();
  133. System.out.println("You were born on "+month +" " + day +"," + year +" You're mighty old!");
  134. }
  135. }
  136.  
  137. Pg 191 Number 22
  138.  
  139. import java.util.*;
  140. public class Pg192_22
  141. {
  142. public static void main(String[] args)
  143. {
  144. Scanner console = new Scanner(System.in);
  145. System.out.println("What is your GPA?");
  146. double GPA = console.nextDouble();
  147. System.out.println("What is your SAT score?");
  148. double SAT = console.nextInt();
  149. if( GPA >= 1.9)
  150. {
  151. System.out.println("You are accepted!");
  152. }
  153. else
  154. {
  155. System.out.println("You are rejected!");
  156. }
  157. if( SAT >= 900)
  158. {
  159. System.out.println("You are accepted!");
  160. }
  161. else
  162. {
  163. System.out.println("You are rejected!");
  164. }
  165. }
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement