Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 2. do while loop
- 3. it is a count controlled loop
- 4. true
- 11. Hello
- Hello
- Hello
- Done
- 12. Hello
- Hello
- Hello
- Done
- 13. 2
- 14. 2033
- 15. i = 4
- sum = 15
- 16.i = 39
- sum = 6
- 17. sum = 30
- 18. sum = 15
- 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 semicolon after the start of the for loop
- 33. it is checking if i is greater than zero which will always be true given that it is scaling up i every iteration
- 35. there are no brackets after the start of the for loop so it is only going to do the sum += i; part
- 38. the part where it is checking for the boolean and where it declares the statement to scale up i have been swapped
- 39. the math works out so that the condition will be met only twice, either change the starting value of i to 0 or have the check be 1 <= 3
- 40. commas were used instead of semicolons when writing the for loop, so change those to semicolons
- 41. i has been declared inside of the for loop, so it is a local variable, so declare i outside of the for loop
- 42. i is being defined twice and it does not like that. take off the int in front of the i in the for loop
- 43. Scanner scan = new Scanner(System.in);
- System.out.println("give me a value greater than ten");
- int initialInput = scan.nextInt();
- int timesRooted;
- while (initialInput <= 10)
- {
- System.out.println ("something greater than ten, dummy!");
- initialInput = scan.nextInt();
- }
- while(initialInput > 1.01)
- {
- initialInput = math.sqrt(initialInput);
- timesRooted++;
- }
- System.out.println("the final square root was equal to " + initialinput);
- System.out.println("your inintial input was square rooted " + timesRooted +" times");
- 46. for(int i = 10; i <=20; i++)
- {
- 0 += i;
- }
- System.out.println("the total is " + i);
- 47. for(int i = 3; i <=7; i++)
- {
- 1 *= i;
- }
- System.out.println("the total is " + i);
- 48. int multiples = 0;
- for(int i = 33; i <=97; i+=7)
- {
- multiples++;
- }
- System.out.println("the total number of multiples is " + multiples);
- 49.Scanner scan = new Scanner(System.in);
- System.out.println(How many times should i print \"HelloWorld\"?");
- int num = scan.nextInt();
- while(!num.isDigit())
- {
- System.out.println("give me an integer");
- num = scan.nextInt();
- }
- for(int time=0; time<num; time++)
- {
- System.out.println("HelloWorld");
- }
- 50. Scanner scan = new Scanner(System.in);
- System.out.println("Give me your word");
- String word = scan.next();
- int length = word.length();
- String newWord = "";
- for(int chair = 0; chair < length; chair++)
- {
- newWord = word.charAt(chair) + " ";
- }
- System.out.println("Your word is now " + newWord);
- 51.Scanner scan = new Scanner(System.in);
- System.out.println("Give me your number to factorial");
- int num = scan.nextInt();
- int factorial = 1;
- for (int num; num >=1; num--)
- {
- factorial *=num;
- }
- System.out.println("The factorial of " + num + "is " + factorial);
- 52. Scanner scan = new Scanner(System.in);
- do
- {
- System.out.println("Give me a number");
- int
- }
- okay this was as far as i got before i realized that you run into the issue of having an int variable be named the same thing with each iteration, thus causing it to constantly swap out the previous entered value. I could not think of a way to circumnavigate this issue.
- Scanner scan = new Scanner(System.in);
- int minimum = 328923;
- for (int i = 1; i <= 10; i++)
- {
- System.out.println("Give me your number to compare");
- int newMin = scan.nextInt;
- if (newMin < minimum)
- {
- newMin = minimum;
- }
- }
- System.out.println("The smallest number is " + minimum);
Add Comment
Please, Sign In to add comment