sudoaptinstallname

Untitled

Jan 25th, 2019
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1.  
  2. 2. do/while
  3.  
  4. 3. count controlled loop
  5.  
  6. 4. true
  7.  
  8. 11.
  9. Hello
  10. Hello
  11. Hello
  12. Done
  13.  
  14. 12.
  15. Hello
  16. Hello
  17. Hello
  18. Done
  19.  
  20. 13. 2
  21.  
  22. 14. 2033
  23.  
  24. 15. 10, 5
  25.  
  26. 16. 60, 40
  27.  
  28. 17. 20 , 10
  29.  
  30. 18. 40, 5
  31.  
  32. 19.
  33. 3
  34. 3
  35. 3
  36. 3
  37. 4
  38.  
  39. 27.
  40. for ( i=0, i<5, i++)
  41.  
  42. 29.
  43. package com.company;
  44.  
  45. public class exercises {
  46. public static void main(String [] args)
  47. {
  48. int sum = 0;
  49. int i;
  50. for(i=0;i<5;i++)
  51. {
  52. sum += i;
  53. }
  54. System.out.print(sum);
  55.  
  56.  
  57. }
  58.  
  59. }
  60.  
  61. 32.
  62. The print statement is not in the loop.
  63. It needs {} brackets.
  64.  
  65. 33.
  66. i will always be larger than 10.
  67.  
  68. 35.
  69. It prints i, not the sum.
  70.  
  71. 38.
  72. Bad syntax.
  73. switch out i<3 and i++
  74.  
  75. 39.
  76. for adds 1 to i before it prints Hello.
  77. So you need an extra iteration.
  78. Lower i to 0 or raise its constraint to 4.
  79.  
  80. 40.
  81. for statement needs semicolons.
  82.  
  83. 41. i isnt declared as an integer.
  84.  
  85. 42. i doesnt need value assignment, just declaration.
Add Comment
Please, Sign In to add comment