A+ Computer Science Worksheet 1 displaying Java code with blank lines for output answers.
A+ Computer Science Worksheet 1 with code snippets and output blanks to fill in, featuring variables and system.out.print statements.
PNG
660×674
29.3 KB
Free · Personal Use
Quality Assured by Worksheets Library Team
Reviewed for educational accuracy and age-appropriateness
ID: #782460
⭐
Show Answer Key & Explanations
Step-by-step solution for: Solved A+ Computer Science - Worksheet 1 DIRECTIONS : Fill | Chegg.com
▼
Show Answer Key & Explanations
Step-by-step solution for: Solved A+ Computer Science - Worksheet 1 DIRECTIONS : Fill | Chegg.com
Let’s go line by line and compute each output carefully. We’ll use the initial values:
- `double z = 94.32;`
- `long x = 98;`
- `int a = 9, b = 4;`
- `char var = 'C';`
We assume each statement happens in order, and some may change variables (like lines 13–15).
---
LINE 1: `System.out.print(5 + 2 * 4);`
Multiplication first: `2 * 4 = 8`, then `5 + 8 = 13`
→ Output: 13
---
LINE 2: `System.out.print(a + (a % b));`
`a = 9`, `b = 4`
`a % b = 9 % 4 = 1` (remainder when 9 divided by 4)
Then: `9 + 1 = 10`
→ Output: 10
---
LINE 3: `System.out.print(b / a);`
`b = 4`, `a = 9`
Integer division: `4 / 9 = 0` (since both are ints, result is int — truncates decimal)
→ Output: 0
---
LINE 4: `System.out.print('B' + 5);`
In Java, `'B'` is a char, which has ASCII value 66.
So: `66 + 5 = 71`
But note: this is integer addition, not string concatenation → prints number 71
→ Output: 71
*(Note: If it were `"B" + 5`, it would be "B5", but here it's single quote → char → numeric)*
---
LINE 5: `System.out.print(4 % 8);`
`4 % 8 = 4` (because 4 divided by 8 is 0 with remainder 4)
→ Output: 4
---
LINE 6: `System.out.print(a % b);`
Same as LINE 2: `9 % 4 = 1`
→ Output: 1
---
LINE 7: `System.out.print(b % a);`
`4 % 9 = 4` (4 divided by 9 is 0 remainder 4)
→ Output: 4
---
LINE 8: `System.out.print(8 % 4);`
`8 % 4 = 0` (8 divides evenly by 4)
→ Output: 0
---
LINE 9: `System.out.print((double)(a / b));`
First: `a / b = 9 / 4 = 2` (integer division)
Then cast to double: `(double)2 = 2.0`
→ Output: 2.0
*(Important: The division happens BEFORE casting, so we lose precision before converting.)*
---
LINE 10: `System.out.print((double)a / b);`
Here, `a` is cast to double FIRST: `(double)9 = 9.0`
Then: `9.0 / 4 = 2.25`
→ Output: 2.25
---
LINE 11: `System.out.print(7.0 / 2);`
`7.0` is double, so `7.0 / 2 = 3.5`
→ Output: 3.5
---
LINE 12: `System.out.print((char)(var + 5));`
`var = 'C'` → ASCII 67
`67 + 5 = 72`
`(char)72 = 'H'`
→ Output: H
---
Now, variable changes start happening:
LINE 13:
```java
a = var + 2;
System.out.println(a);
```
`var = 'C'` → ASCII 67
`67 + 2 = 69`
Assign to `a`: now `a = 69`
Print `a` → Output: 69
*(Note: This changes the value of `a` for any future use — but no more uses after this except possibly implicit ones? Let’s check next lines.)*
---
LINE 14:
```java
z = var + 5;
System.out.println(z);
```
`var = 'C'` → 67
`67 + 5 = 72`
Assign to `z` (which is double): `z = 72.0`
Print `z` → Output: 72.0
*(Note: Even though 72 is whole number, since z is double, it prints as 72.0)*
---
LINE 15:
```java
var = 'A' + 4;
System.out.println(var);
```
`'A'` is ASCII 65
`65 + 4 = 69`
Assign to `var`: `var = (char)69 = 'E'`
Print `var` → Output: E
---
Now let’s collect all outputs in order:
1. 13
2. 10
3. 0
4. 71
5. 4
6. 1
7. 4
8. 0
9. 2.0
10. 2.25
11. 3.5
12. H
13. 69
14. 72.0
15. E
Wait — let me double-check LINE 4 again.
LINE 4: `'B' + 5`
ASCII of 'B' is 66 → 66 + 5 = 71 → correct.
LINE 12: `'C' + 5 = 67 + 5 = 72 → 'H' → correct.
LINE 13: `a = var + 2 = 67 + 2 = 69 → print 69 → correct.
LINE 14: `z = var + 5 = 67 + 5 = 72 → stored as double → prints 72.0 → correct.
LINE 15: `'A' + 4 = 65 + 4 = 69 → char 69 is 'E' → correct.
All looks good.
Final Answer:
1. 13
2. 10
3. 0
4. 71
5. 4
6. 1
7. 4
8. 0
9. 2.0
10. 2.25
11. 3.5
12. H
13. 69
14. 72.0
15. E
- `double z = 94.32;`
- `long x = 98;`
- `int a = 9, b = 4;`
- `char var = 'C';`
We assume each statement happens in order, and some may change variables (like lines 13–15).
---
LINE 1: `System.out.print(5 + 2 * 4);`
Multiplication first: `2 * 4 = 8`, then `5 + 8 = 13`
→ Output: 13
---
LINE 2: `System.out.print(a + (a % b));`
`a = 9`, `b = 4`
`a % b = 9 % 4 = 1` (remainder when 9 divided by 4)
Then: `9 + 1 = 10`
→ Output: 10
---
LINE 3: `System.out.print(b / a);`
`b = 4`, `a = 9`
Integer division: `4 / 9 = 0` (since both are ints, result is int — truncates decimal)
→ Output: 0
---
LINE 4: `System.out.print('B' + 5);`
In Java, `'B'` is a char, which has ASCII value 66.
So: `66 + 5 = 71`
But note: this is integer addition, not string concatenation → prints number 71
→ Output: 71
*(Note: If it were `"B" + 5`, it would be "B5", but here it's single quote → char → numeric)*
---
LINE 5: `System.out.print(4 % 8);`
`4 % 8 = 4` (because 4 divided by 8 is 0 with remainder 4)
→ Output: 4
---
LINE 6: `System.out.print(a % b);`
Same as LINE 2: `9 % 4 = 1`
→ Output: 1
---
LINE 7: `System.out.print(b % a);`
`4 % 9 = 4` (4 divided by 9 is 0 remainder 4)
→ Output: 4
---
LINE 8: `System.out.print(8 % 4);`
`8 % 4 = 0` (8 divides evenly by 4)
→ Output: 0
---
LINE 9: `System.out.print((double)(a / b));`
First: `a / b = 9 / 4 = 2` (integer division)
Then cast to double: `(double)2 = 2.0`
→ Output: 2.0
*(Important: The division happens BEFORE casting, so we lose precision before converting.)*
---
LINE 10: `System.out.print((double)a / b);`
Here, `a` is cast to double FIRST: `(double)9 = 9.0`
Then: `9.0 / 4 = 2.25`
→ Output: 2.25
---
LINE 11: `System.out.print(7.0 / 2);`
`7.0` is double, so `7.0 / 2 = 3.5`
→ Output: 3.5
---
LINE 12: `System.out.print((char)(var + 5));`
`var = 'C'` → ASCII 67
`67 + 5 = 72`
`(char)72 = 'H'`
→ Output: H
---
Now, variable changes start happening:
LINE 13:
```java
a = var + 2;
System.out.println(a);
```
`var = 'C'` → ASCII 67
`67 + 2 = 69`
Assign to `a`: now `a = 69`
Print `a` → Output: 69
*(Note: This changes the value of `a` for any future use — but no more uses after this except possibly implicit ones? Let’s check next lines.)*
---
LINE 14:
```java
z = var + 5;
System.out.println(z);
```
`var = 'C'` → 67
`67 + 5 = 72`
Assign to `z` (which is double): `z = 72.0`
Print `z` → Output: 72.0
*(Note: Even though 72 is whole number, since z is double, it prints as 72.0)*
---
LINE 15:
```java
var = 'A' + 4;
System.out.println(var);
```
`'A'` is ASCII 65
`65 + 4 = 69`
Assign to `var`: `var = (char)69 = 'E'`
Print `var` → Output: E
---
Now let’s collect all outputs in order:
1. 13
2. 10
3. 0
4. 71
5. 4
6. 1
7. 4
8. 0
9. 2.0
10. 2.25
11. 3.5
12. H
13. 69
14. 72.0
15. E
Wait — let me double-check LINE 4 again.
LINE 4: `'B' + 5`
ASCII of 'B' is 66 → 66 + 5 = 71 → correct.
LINE 12: `'C' + 5 = 67 + 5 = 72 → 'H' → correct.
LINE 13: `a = var + 2 = 67 + 2 = 69 → print 69 → correct.
LINE 14: `z = var + 5 = 67 + 5 = 72 → stored as double → prints 72.0 → correct.
LINE 15: `'A' + 4 = 65 + 4 = 69 → char 69 is 'E' → correct.
All looks good.
Final Answer:
1. 13
2. 10
3. 0
4. 71
5. 4
6. 1
7. 4
8. 0
9. 2.0
10. 2.25
11. 3.5
12. H
13. 69
14. 72.0
15. E
Parent Tip: Review the logic above to help your child master the concept of answers for science worksheet.