liangm20

Unit 3: Skill Practice

Oct 3rd, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. Unit 3 Skill Practice
  2. ***multiple choice questions 6,7,8,13 have already been done before***
  3. 17. 5
  4. 18. 2.0
  5. 19. 3.141592653589793
  6. 20. 6
  7. 21. 4
  8. 22. 8
  9. 23. 8.0
  10. 28. System.out.print("\"Welcome " + "to " + "Java " + "Illuminated\"");
  11. 29. int i = Math.min(3,5);
  12. System.out.print(i);
  13. 30. double d = 5.0;
  14. System.out.print(Math.sqrt(d));
  15. 31.
  16. import java.util.*;
  17. public class scanner
  18. {
  19. public static void main (String [] args)
  20. {
  21. Scanner console = new Scanner(System.in);
  22. System.out.println("Type in a value.");
  23. int x = console.nextInt();
  24. System.out.println("Type in another value.");
  25. int y = console.nextInt();
  26. System.out.print("The minimum is " + Math.min(x,y));
  27. }
  28. }
  29. 32.
  30. import java.util.*;
  31. public class 3scanner
  32. {
  33. public static void main (String [] args)
  34. {
  35. Scanner console = new Scanner (System.in);
  36. System.out.println("Type in a value");
  37. int x = console.nextInt();
  38. System.out.println("Type in another value.");
  39. int y = console.nextInt();
  40. System.out.println("Type in a third value.");
  41. int x = console.nextInt();
  42. System.out.print("The maximum of the three values is " + Math.max(x,y,z));
  43. }
  44. }
  45. 34.
  46. import java.util.*;
  47. public class doubleScanner
  48. {
  49. public static void main (String [] args)
  50. {
  51. Scanner console = new Scanner (System.in);
  52. System.out.println("Type in a value.");
  53. double x = console.nextDouble();
  54. System.out.println("The square of the value is " + x*x);
  55. }
  56. }
  57. 40. data type short cannot have a decimal point; should be either float or double
  58. 41. int should be double
  59. 42. should be Math.PI
  60. 46. math should be capitalized, should be Math.sqrt(6);
  61. 47. shouldn't be parentheses after Math.PI, take out parentheses
  62. 48. e should be capitalized, should be Math.E;
  63. 53.
  64. import java.util.*;
  65. public class question53
  66. {
  67. int rand;
  68. int x;
  69. int y;
  70. public static void randomNumber() //this is the random method
  71. {
  72. Random rand = new Random();
  73. int x = rand.nextInt(101);
  74. System.out.println("One of the 2 random numbers is " + x);
  75. Random rand2 = new Random();
  76. int y = rand.nextInt(101);
  77. System.out.println("The other random number is " + y);
  78. System.out.print("The minimum of the two numbers is " + Math.min(x,y));
  79.  
  80. }
  81. }
  82. 54.
  83. import java.util.*;
  84. public class question54
  85. {
  86. public static void scannerMethod() //this is the scanner
  87. {
  88. Scanner console = new Scanner(System.in);
  89. System.out.println("Type in any number.");
  90. double x = console.nextInt();
  91. System.out.println("The cube of the number is " + x*x*x);
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment