正确注册名字

import java.util.Scanner;

public class S3 {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        while(true){
            System.out.println("请输出姓名:");
            String name = scanner.nextLine().trim();
            if (name.matches("^[a-zA-Z]{6,20}+|[\\u4e00-\\u9fa5]{2,6}$")){
                System.out.printf("恭喜: %s,注册成功. %n",name);
            } else {
                System.out.printf("失败: %s, 注册失败,姓名填写不规范. %n",name );
            }
            System.out.println();
            System.out.println();;
        }
    }
}

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的 MATLAB GUI 界面,其中包括一个文本输入框和一个按钮,可以在文本框中输入名字,并将其打印到 MATLAB 命令窗口中。 ```matlab function varargout = register_gui(varargin) % REGISTER_GUI MATLAB code for register_gui.fig % REGISTER_GUI, by itself, creates a new REGISTER_GUI or raises the existing % singleton*. % % H = REGISTER_GUI returns the handle to a new REGISTER_GUI or the handle to % the existing singleton*. % % REGISTER_GUI('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in REGISTER_GUI.M with the given input arguments. % % REGISTER_GUI('Property','Value',...) creates a new REGISTER_GUI or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before register_gui_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to register_gui_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Edit the above text to modify the response to help register_gui % Last Modified by GUIDE v2.5 12-Jul-2021 10:54:04 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @register_gui_OpeningFcn, ... 'gui_OutputFcn', @register_gui_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before register_gui is made visible. function register_gui_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to register_gui (see VARARGIN) % Choose default command line output for register_gui handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes register_gui wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = register_gui_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; % --- Executes on button press in register_button. function register_button_Callback(hObject, eventdata, handles) % hObject handle to register_button (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Read the string from the text input box name = get(handles.name_input, 'String'); % Print the name to the MATLAB command window disp(['Name: ' name]); function name_input_Callback(hObject, eventdata, handles) % hObject handle to name_input (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of name_input as text % str2double(get(hObject,'String')) returns contents of name_input as a double % --- Executes during object creation, after setting all properties. function name_input_CreateFcn(hObject, eventdata, handles) % hObject handle to name_input (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end ``` 在这个 GUI 界面中,名字输入框的句柄为 `name_input`,注册按钮的句柄为 `register_button`。在 `register_button_Callback` 回调函数中,使用 `get` 函数获取名字输入框中的字符串,并使用 `disp` 函数将其打印到 MATLAB 命令窗口中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值