Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 2. do/while
- 3. count-controlled loop
- 4. true
- 11. Hello
- Hello
- Hello
- Done
- 12. Hello
- Hello
- Hello
- Done
- 13. 2
- 14. 2033
- 15. i is 4 and sum is 10
- 16. i is 39 and sum is 60
- 17. sum is 45
- 18. sum is 40
- 19. 3
- 3
- 3
- 3
- 4
- 27. for( int i = 0; i < 5; i++){
- System.out.println("Hi there");
- }
- 29. int sum = 0;
- for( int i = 1; i <= 5; i++){
- sum +=i;
- }
- 32. There is a semi colon after the parentheses of the for loop.
- 33. because i is greater than zero and increments, the loop will continue forever.
- 35. i is a local variable and can't be used outside of the for loop.
- 38. the program is reading the incrementor and the limit in the wrong order and place. place the i++ after the i < 3.
- 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.
- 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.
- 41. i is a local variable and can't be used outside of the for loop.
- 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.
- 43. Scanner input = new Scanner(System.in);
- System.out.println("Type a number greater than 10");
- int i = input.nextInt();
- int counter = 0;
- while(i<=10){
- System.out.println("Invalid input. Please type a number greater than 10.");
- i = input.nextInt();
- }
- while(i > 1.01){
- i = Math.sqrt(i);
- counter ++;
- }
- System.out.println("It took "+counter+" number of tries for i to be less than 1.01");
- 46. int sum = 0;
- for( int i = 10; i <= 20; i++){
- sum +=i;
- }
- System.out.println("The sum is "+counter);
- 47. int product = 1;
- for( int i = 3; i <= 7; i++){
- product *=i;
- }
- System.out.println("The product is "+product);
- 48. int multiple = 33;
- int counter = 0;
- while(multiple <= 97){
- multiple += 7;
- counter ++;
- }
- System.out.println("The are "+counter+" multiples between 33 and 97");
- 49. Scanner input = new Scanner(System.in);
- System.out.println("Type a number");
- int n = input.nextInt();
- int counter = 1;
- if(n != (int)n){
- System.out.println("Invalid input. Please type another number");
- n = input.nextInt();
- }
- while(counter <= n){
- System.out.println("Hello World");
- counter ++;
- }
- 50. Scanner input = new Scanner(System.in);
- System.out.println("Type a word");
- String word = input.next();
- int length = word.length();
- int counter = 0;
- while(counter <= length){
- System.out.println(word.charAt(counter));
- System.out.println(" ");
- counter++;
- }
- 51. Scanner input = new Scanner(System.in);
- System.out.println("Type a number");
- int i = input.nextInt();
- int product = 1;
- for( i; i > 0; i-- ){
- product *=i;
- }
- System.out.println("Your number factorial is "+product);
- 52. Scanner input = new Scanner(System.in);
- int min = 2000;
- System.out.println("Please type a number less than 2000");
- int n = input.nextInt();
- int counter = 1;
- while(counter <= 10){
- if(n < min){
- min = n;
- }
- System.out.println("Please type another number less than 2000");
- int n = input.nextInt();
- counter++;
- }
- System.out.println("The smallest number that you typed is "+min);
- RAW Paste Data
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement