我需要一个代码在控制台中编写String并与Array进行比较。
String Array = {"skill"};
Console co=System.console();
然后将Array与co ...进行比较
答案 0 :(得分:5)
这是一个从键盘读取字符串并将字符串与另一个字符串
进行比较的示例import java.util.Scanner;
public class Main
{
public static void main(String args[])
{
String input = null;
String compareString = "hello world";
Scanner inputReader = new Scanner(System.in);
System.out.println("please enter: hello world" );
// here is how you take the input from keyboard
input = inputReader.nextLine();
// this is how you write to console
System.out.println("You entered :" + input);
//Here is how you compare two string
if(compareString.equals(input))
{
System.out.println("input is: hello world");
}
else
{
System.out.println("input is not: hello world");
}
}
}
Execution1:
Please enter: hello world
输入:
hello world
输出:
You entered :hello world
input is: hello world
Execution2:
Please enter: hello world
输入:
hello
输出:
You entered :hello
input is not: hello world
答案 1 :(得分:0)