Advertisement
Arush22

Untitled

Jan 26th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.57 KB | None | 0 0
  1. 2. do/while
  2. 3. count-controlled loop
  3. 4. true
  4. 11. Hello
  5. Hello
  6. Hello
  7. Done
  8. 12. Hello
  9. Hello
  10. Hello
  11. Done
  12. 13. 2
  13. 14. 2033
  14. 15. i is 4 and sum is 10
  15. 16. i is 39 and sum is 60
  16. 17. sum is 45
  17. 18. sum is 40
  18. 19. 3
  19. 3
  20. 3
  21. 3
  22. 4
  23. 27. for( int i = 0; i < 5; i++){
  24. System.out.println("Hi there");
  25. }
  26. 29. int sum = 0;
  27. for( int i = 1; i <= 5; i++){
  28. sum +=i;
  29. }
  30. 32. There is a semi colon after the parentheses of the for loop.
  31. 33. because i is greater than zero and increments, the loop will continue forever.
  32. 35. i is a local variable and can't be used outside of the for loop.
  33. 38. the program is reading the incrementor and the limit in the wrong order and place. place the i++ after the i < 3.
  34. 39. Because i is an int that must be less than 3 for the loop to execute, and 3 is not less than 3, the loop did not execute a third time. Change the < to <= in the for loop.
  35. 40. you place commas instead of semi colons so it doesn't know where the statements end. replace the commas in the for loop with semi colons.
  36. 41. i is a local variable and can't be used outside of the for loop.
  37. 42. You already declared a variable name i above, and you can't name two variable with the same name in one class. Remove the int in front of the i when initiating the i in the for loop.
  38.  
  39. 43. Scanner input = new Scanner(System.in);
  40. System.out.println("Type a number greater than 10");
  41. int i = input.nextInt();
  42. int counter = 0;
  43. while(i<=10){
  44. System.out.println("Invalid input. Please type a number greater than 10.");
  45. i = input.nextInt();
  46. }
  47. while(i > 1.01){
  48. i = Math.sqrt(i);
  49. counter ++;
  50. }
  51. System.out.println("It took "+counter+" number of tries for i to be less than 1.01");
  52.  
  53. 46. int sum = 0;
  54. for( int i = 10; i <= 20; i++){
  55. sum +=i;
  56. }
  57. System.out.println("The sum is "+counter);
  58.  
  59. 47. int product = 1;
  60. for( int i = 3; i <= 7; i++){
  61. product *=i;
  62. }
  63. System.out.println("The product is "+product);
  64.  
  65. 48. int multiple = 33;
  66. int counter = 0;
  67. while(multiple <= 97){
  68. multiple += 7;
  69. counter ++;
  70. }
  71. System.out.println("The are "+counter+" multiples between 33 and 97");
  72.  
  73. 49. Scanner input = new Scanner(System.in);
  74. System.out.println("Type a number");
  75. int n = input.nextInt();
  76. int counter = 1;
  77. if(n != (int)n){
  78. System.out.println("Invalid input. Please type another number");
  79. n = input.nextInt();
  80. }
  81. while(counter <= n){
  82. System.out.println("Hello World");
  83. counter ++;
  84. }
  85.  
  86. 50. Scanner input = new Scanner(System.in);
  87. System.out.println("Type a word");
  88. String word = input.next();
  89. int length = word.length();
  90. int counter = 0;
  91. while(counter <= length){
  92. System.out.println(word.charAt(counter));
  93. System.out.println(" ");
  94. counter++;
  95. }
  96.  
  97. 51. Scanner input = new Scanner(System.in);
  98. System.out.println("Type a number");
  99. int i = input.nextInt();
  100. int product = 1;
  101. for( i; i > 0; i-- ){
  102. product *=i;
  103. }
  104. System.out.println("Your number factorial is "+product);
  105.  
  106. 52. Scanner input = new Scanner(System.in);
  107. int min = 2000;
  108. System.out.println("Please type a number less than 2000");
  109. int n = input.nextInt();
  110. int counter = 1;
  111. while(counter <= 10){
  112. if(n < min){
  113. min = n;
  114. }
  115. System.out.println("Please type another number less than 2000");
  116. int n = input.nextInt();
  117. counter++;
  118. }
  119. System.out.println("The smallest number that you typed is "+min);
  120. RAW Paste Data
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement