AP CS A Free Response Questions 50
AP CS A Free Response Questions 50
1. Create an int variable with value 100 and assign it to a double variable, then print it.
2. Create a double variable with value 12.99, convert it to int, and print it.
3. Declare two int variables (35 and 8). Perform addition, subtraction, multiplication, and division.
5. Define a final variable for GRAVITY (9.8) and use it to calculate force (Force = Mass * Gravity).
7. Declare a String with "Object-Oriented Programming" and print the index of "Programming".
8. Compare "grape" and "melon" using compareTo() and print which comes first alphabetically.
9. Declare a double with 49.0 and print its square root using Math.sqrt().
10. Declare a double with -3.14 and print its absolute value using Math.abs().
11. Declare an int variable with value 25. If greater than 20, print "Big number", else print "Small
number".
12. Create a boolean variable isWeekend = false. Print "Relaxing day" if true, otherwise "Work time".
13. Store a student grade as an int. Print "Excellent" for 90+, "Good" for 70+, otherwise "Needs
improvement".
14. Declare a boolean variable isRaining = false. Print "It's a sunny day" if not raining.
15. Declare an int variable with a random value. Print "Medium range" if between 50 and 100.
16. Use a for loop to count backward from 10 to 1 and print the numbers.
18. Declare an int with value 5 and use a while loop to increase it up to 20, printing each value.
19. Use nested for loops to print a 5x5 star (*) matrix.
20. Use a for loop to print numbers from 1 to 15 but only display up to 10.
21. Declare two int variables. If one is divisible by the other, print "Divisible".
22. Create a double variable with 2.718 and convert it to int before printing.
23. Declare an int variable with a random value. Print "Even" if even, otherwise "Odd".
25. Use a while loop to repeatedly prompt a user for correct input until it's valid.
29. Use a for loop to calculate the sum of numbers from 1 to 50.
32. Use a for loop to print the squares of numbers from 1 to 10.
34. Use a for loop to print a right-angled triangle pattern with * symbols.
35. Declare a String variable with "Java is powerful" and find the index of "powerful".
38. Write an if-else statement to compare three numbers and print the largest.
39. Declare two int variables and swap their values without using a third variable.
41. Write an if-else statement to classify a triangle based on three given sides.
42. Declare a String variable with "Hello World!" and replace "World" with "Java".
43. Use a for loop to find the largest element in an array of integers.