java为了方便将抽奖结果及时反馈给用户,商场注册时要求提供身份证号和电话;要求身份证号必须是15位和18位,手机必须是11位;座机必须以字符串“-”连接'-‘’前必须是4位数,“-”后必须是七位数
时间: 2024-06-12 22:05:50 浏览: 4
。以下是Java代码实现:
```
import java.util.Scanner;
public class Lottery {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("欢迎参加本次抽奖活动,请输入您的注册信息:");
System.out.print("请输入身份证号码:");
String idNumber = input.nextLine();
while (idNumber.length() != 15 && idNumber.length() != 18) {
System.out.print("身份证号码格式不正确,请重新输入:");
idNumber = input.nextLine();
}
System.out.print("请输入手机号码:");
String phoneNumber = input.nextLine();
while (phoneNumber.length() != 11) {
System.out.print("手机号码格式不正确,请重新输入:");
phoneNumber = input.nextLine();
}
System.out.print("请输入座机号码:");
String landlineNumber = input.nextLine();
while (!landlineNumber.matches("\\d{4}-\\d{7}")) {
System.out.print("座机号码格式不正确,请重新输入:");
landlineNumber = input.nextLine();
}
System.out.println("您的注册信息如下:");
System.out.println("身份证号码:" + idNumber);
System.out.println("手机号码:" + phoneNumber);
System.out.println("座机号码:" + landlineNumber);
System.out.println("恭喜您获得了一次抽奖机会,请等待开奖结果。");
}
}
```
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)