把这段C++代码转换成Java代码
时间: 2024-04-14 09:06:20 浏览: 231
把这段C++代码转换成Java代码:
```cpp
#include <iostream>
using namespace std;
int main() {
int a = 5;
float b = 3.5;
double c = 2.3456;
char d = 'A';
cout << "a = " << a << endl;
cout << "b = " << b << endl;
cout << "c = " << c << endl;
cout << "d = " << d << endl;
return 0;
}
```
Java代码:
```java
public class Main {
public static void main(String[] args) {
int a = 5;
float b = 3.5f;
double c = 2.3456;
char d = 'A';
System.out.println("a = " + a);
System.out.println("b = " + b);
System.out.println("c = " + c);
System.out.println("d = " + d);
}
}
```
注意,在Java中,float类型的变量需要在数字后面加上f或F,否则会被认为是double类型。此外,Java中的控制台输出使用System.out.println()函数。
阅读全文