电脑编程

时间:2025-01-26 00:53:25 网络游戏

打印 "Hello, World!"

Python:

```python

print("Hello, World!")

```

Java:

```java

public class HelloWorld {

public static void main(String[] args) {

System.out.println("Hello, World!");

}

}

```

C++:

```cpp

include

int main() {

std::cout << "Hello, World!" << std::endl;

return 0;

}

```

JavaScript:

```javascript

console.log("Hello, World!");

```

计算两个数的和

Python:

```python

a = 10

b = 20

sum = a + b

print("两个数的和为:", sum)

```

Java:

```java

public class SumCalculator {

public static void main(String[] args) {

int a = 10;

int b = 20;

int sum = a + b;

System.out.println("两个数的和为: " + sum);

}

}

```

C++:

```cpp

include

int main() {

int a = 10;

int b = 20;

int sum = a + b;

std::cout << "两个数的和为: " << sum << std::endl;

return 0;

}

```

JavaScript:

```javascript

var a = 10;

var b = 20;

var sum = a + b;

console.log("两个数的和为: " + sum);

```

判断一个数是否为偶数

Python:

```python

num = int(input("请输入一个整数: "))

if num % 2 == 0:

print(num, "是偶数")

else:

print(num, "是奇数")

```

Java:

```java

import java.util.Scanner;

public class EvenOddChecker {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

System.out.print("请输入一个整数: ");

int num = scanner.nextInt();

if (num % 2 == 0) {

System.out.println(num + " 是偶数");

} else {

System.out.println(num + " 是奇数");

}

}

}

```

C++:

```cpp

include

int main() {

int num;

std::cout << "请输入一个整数: ";

std::cin >> num;

if (num % 2 == 0) {

std::cout << num << " 是偶数" << std::endl;

} else {

std::cout << num << " 是奇数" << std::endl;

}

return 0;

}

```

JavaScript:

```javascript

var num = parseInt(prompt("请输入一个整数:"));

if (num % 2 === 0) {

alert(num + " 是偶数");

} else {

alert(num + " 是奇数");

}

```

打印九九乘法表

Python:

```python

for i in range(1, 10):

for j in range(1, i + 1):

print("%d * %d = %d" % (j, i, j * i), end=" ")

print()

```

Java: