slug
type
status
category
date
summary
tags
password
icon
以下是 六 道 AP Computer Science A(CSA)风格的练习题,专门针对 Implementing String Algorithms(字符串算法实现) 与 Nested Iteration(嵌套循环) 设计的。
题目难度从基础到中等偏上,涵盖考试常见考点。每题都附带简短说明或提示。
🧩 Part 1: Implementing String Algorithms
Q1. Count Vowels
Write a method
countVowels(String s)
that returns the number of vowels (a, e, i, o, u
) in the string s
.Example:
countVowels("Computer Science") → 6
Q2. Reverse a String
Write a method
reverse(String s)
that returns the reversed version of s
.Example:
reverse("Java") → "avaJ"
Q3. Check Palindrome
Write a method
isPalindrome(String s)
that returns true
if s
is the same forward and backward, ignoring case.Example:
isPalindrome("RaceCar") → true
🔁 Part 2: Nested Iteration (Loops Inside Loops)
Q4. Count Repeated Letters
Write a method
countRepeatedPairs(String s)
that counts how many pairs of adjacent identical letters appear in the string.Example:
countRepeatedPairs("bookkeeper") → 3
(pairs: "oo", "kk", "ee")
Q5. Print Character Grid
Write nested loops to print the following pattern for a given integer
n
:Q6. Triangle of Letters
Use nested loops to print a triangle pattern:
Solutions
Solutions
下面给出前面 10 道题的 完整 Java 解答(含少量注释与简单测试)。你可以将整段保存为
APStringNestedSolutions.java
直接运行。- 作者:现代数学启蒙
- 链接:https://www.math1234567.com/article/exercieses
- 声明:本文采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处。