模拟生成订单号 小票上有年月日和时间信息,将其拼接成字符串。 例如:arr={2023,0506,1557},拼接成s:[202305061557],并打印出来。 如果可以,最好使用Scanner录入三个信息。
时间: 2024-05-15 22:13:55 浏览: 109
可以使用Scanner来录入三个信息,然后将它们拼接成字符串。以下是示例代码:
```java
import java.util.Scanner;
public class OrderNumberGenerator {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入年份(四位数字):");
int year = scanner.nextInt();
System.out.println("请输入月份(两位数字):");
int month = scanner.nextInt();
System.out.println("请输入日期(两位数字):");
int day = scanner.nextInt();
System.out.println("请输入时间(四位数字):");
int time = scanner.nextInt();
scanner.close();
String s = String.format("%04d%02d%02d%04d", year, month, day, time);
System.out.println("生成的订单号为:" + s);
}
}
```
运行示例:
```
请输入年份(四位数字):
2023
请输入月份(两位数字):
05
请输入日期(两位数字):
06
请输入时间(四位数字):
1557
生成的订单号为:202305061557
```
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231044901.png)
![-](https://img-home.csdnimg.cn/images/20241231045021.png)
![-](https://img-home.csdnimg.cn/images/20241231044901.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![tgz](https://img-home.csdnimg.cn/images/20250102104920.png)
![](https://img-home.csdnimg.cn/images/20250102104920.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044901.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)