Advertisement
zainarfi00

Chapter 5 Excercises

Nov 3rd, 2015
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. Exercises Chapter 5
  2. Number 2
  3.  
  4.  
  5.  
  6. Number 4
  7. public class Pg378_4
  8. {
  9. public static void randomX(int a, int b)
  10. {
  11. Random rand = new Random
  12. int x = rand.nextInt(16);
  13. while(a <= 16)
  14. {
  15. for(int a; a<= 16; a++)
  16. {
  17. System.out.println("x);
  18. }
  19. }
  20. }
  21. }
  22.  
  23.  
  24. Number 6
  25.  
  26. public class Pg378_6
  27. {
  28. public static void makeGuesses()
  29. {
  30. while(x >= 48)
  31. {
  32. x = rand.nextInt(50) + 1;
  33. System.out.println("Guess = " + x);
  34. a++;
  35. }
  36. System.out.println("total guesses = " + a);
  37. }
  38. }
  39.  
  40. Number 8
  41.  
  42. public class Pg379_8
  43. {
  44. public static void randomWalk()
  45. {
  46. while(x > -3 || x < 3)
  47. {
  48. int a = 0
  49. x = rand.nextInt(1)
  50. if(x == 1)
  51. {
  52. a++;
  53. System.out.println("postion = " + a);
  54. }
  55. else
  56. {
  57. a--;
  58. System.out.println("postion = " + a);
  59. }
  60. }
  61. }
  62.  
  63.  
  64. Number 10
  65.  
  66.  
  67.  
  68. Number 12
  69. public class Pg380_12
  70. {
  71. public static void printAverage()
  72. {
  73. while( x > 0)
  74. {
  75. Scanner console = new Scanner(System.in);
  76. System.out.println("Guess = ");
  77. for(int i = 1; i <= x; i ++)
  78. int xi = console.nextInt;
  79. System.out.print(x);
  80. }
  81. average=(x1+x2+x3)/2;
  82. System.out.println(average);
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement