package cn.itcast.chapter04;
import java.util.Scanner;
public class Exom05 {
public static void main(String[] args) {
String[] str = new String[20];
int m;
Scanner sc =new Scanner(System.in);
System.out.print("輸入密碼個數n:");
int n =sc.nextInt();
for(int i = 0;i < n; i++)
{System.out.println("輸入密碼第"+(i+1)+"個");
str[i]= sc.nextLine();
}
System.out.print("輸入密碼");
String str2 = new String(sc.nextLine());
m=0;
for(int i =0; i<n; i++)
{
if(str2.contains(str[i])) m=1;
}
if(m==1) System.out.print("輸入密碼正確");
else System.out.print("輸入密碼不正確");
}
}
uj5u.com熱心網友回復:
在int n =sc.nextInt();之后加上一句 sc.nextLine(); //去掉接收int資料后殘留在輸入快取的回車換行符uj5u.com熱心網友回復:
我知道哪里錯了
應該是str[i]=sc. next()
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/101844.html
標籤:Eclipse
上一篇:java求助大佬
