Computer Applications: Loops & Programs
Computer Applications: Loops & Programs
Assign numbers to mutability: if the choice is 1, iterate from 1 to 100 and apply the prime checking condition (only divisible by 1 and itself). If choice is 2, use a similar iteration to identify non-primes. Implement logic within a switch-case to separate outputs based on user input choice.
The loop decreases `p` by 20 with each iteration. Starting from 200, `p` becomes 180, 160, 140, 120, and finally 100. The loop exits when `p-20` equals 80 which is less than 100. `System.out.println(p);` outputs 80.
Initialize `f` to 1 and `i` to 1. Use `while(i <= 5)` and inside the loop, multiply `f` by `i` for the factorial, print `f`, then increment `i`. This structure echoes the iterative multiplication of the for-loop.
To implement this, initialize sum as 0. Iterate a loop from 1 to 20. If the counter variable is odd, add 2 to sum, else subtract 2 from sum. Initialize x to 2 because all series elements are 2. Final sum will be calculated considering the alternation pattern with even elements subtracted.
The variable `m` will increment 4 times in the loop, resulting in `m = 6`. The expression `--n` executes once after the loop ends, so `n` becomes 14. Therefore, the output will be `m=6` and `n=14`.
The inner loop will execute 0 times when `i=3` because its condition `j<i` becomes `j<3` but starts from `j=2`, hence running once and printing an empty string. With `i=4`, it runs twice. The outer loop prints "WIN" each time. Output will be: WIN WIN
The loop will execute `i` from 0 to 1 and `j` from 1 to 2. The output will be: ``` i:0 j:1 i:1 j:2 ```The loop stops because `j` becomes 3, which fails the loop condition `j<3`.
Initialize `x` to 10 and `c` to 20. Use `while(c >= 10)`, increment `x`, and `decrement c` by 2 inside the loop body. This conversion keeps the loop condition and body behavior consistent with the original for-loop.
The outer loop will execute 0 times because the loop condition `a <= 4` is false initially as `a` is initialized to 6. Therefore, the statement `System.out.println(a);` will output 6.
A tech number is a number with an even number of digits that can be split into two equal halves, and the square of their sum equals the number itself. To identify four-digit tech numbers, iterate over all four-digit numbers, split each into two halves, compute the sum and its square. If this square equals the original number, it is a tech number. Examples are 2025, 3025, and 9801.