7-2 判断登录信息--Java字符串比较

题目要求:

从键盘接收用户输入的两个字符串,第一个代表用户名,第二个代表密码。
(1)如果用户名是SwpuIot,并且密码是123456,则输出:Welcome
(2)如果用户名正确,密码不正确,输出:Mismatch
(3)其他情况下,输出:NotExist
要输出的信息,建议从题目中复制,确保精确匹配。

输入格式:

用空格分隔开的两个字符串。

输出格式:

首字母大写的一个单词或词组。

输入样例:

SwpuIot 123456

输出样例:

Welcome

代码块:

import java.util.Scanner;
public class LoginInformation {
	public static void main(String[] args) {
		String str = "SwpuIot 123456";
		String[] strs = str.split(" ");
		
		Scanner sc = new Scanner(System.in);
		String s1 = sc.next();
		String s2 = sc.next();
		sc.close();
		
		if(strs[0].equals(s1) && strs[1].equals(s2)) {
			System.out.println("Welcome");
		}else if(strs[0].equals(s1) && !strs[1].equals(s2)) {
			System.out.println("Mismatch");
		}else {
			System.out.println("NotExist");
		}
		
	}
}
原创文章 14 获赞 12 访问量 1199

猜你喜欢

转载自blog.csdn.net/weixin_45713984/article/details/106042947