编程题打印字母表怎么打

时间:2025-01-28 18:09:52 网络游戏

1. C++

```cpp

include

using namespace std;

int main() {

char a;

int x = 0;

// 正序打印字母表

for (a = 'a'; a = 'a' - 1; a--) {

cout << a;

x++;

if (x == 13) {

cout << endl;

x = 0;

}

}

return 0;

}

```

2. Python

```python

for i in range(26):

print(chr(i + ord('a')), end=' ')

print()

for i in range(26):

print(chr(i + ord('A')), end=' ')

print()

```

3. Java

```java

public class AlphabetDemo {

public static void main(String[] args) {

for (char c = 'a'; c <= 'z'; c++) {

System.out.println("value: " + (int) c + " char: " + c);

}

for (char c = 'A'; c <= 'Z'; c++) {

System.out.println("value: " + (int) c + " char: " + c);

}

}

}

```

4. JavaScript

```javascript

for (let i = 0; i < 26; i++) {

console.log(`value: ${i + 97} char: ${String.fromCharCode(i + 97)}`);

}

for (let i = 0; i < 26; i++) {

console.log(`value: ${i + 65} char: ${String.fromCharCode(i + 65)}`);

}

```

5. C

```csharp

using System;

class Program {

static void Main() {

for (char c = 'a'; c <= 'z'; c++) {

Console.WriteLine($"value: {c} char: {c}");

}

for (char c = 'A'; c <= 'Z'; c++) {

Console.WriteLine($"value: {c} char: {c}");

}

}

}

```

6. Ruby

```ruby

for i in 0..25

puts "value: {i + 97} char: {i + 97}"

end

for i in 0..25

puts "value: {i + 65} char: {i + 65}"

end

```

这些示例展示了如何在不同的编程语言中打印字母表。你可以根据自己的需求和使用的编程语言选择合适的方法。