I need a code to write String in the console and making compare with Array.
String Array = {"skill"};
Console co=System.console();
then compare Array with co...
I need a code to write String in the console and making compare with Array.
String Array = {"skill"};
Console co=System.console();
then compare Array with co...
here is an example to read a string from the keyboard and compare the string with another string
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
Input:
hello world
output:
You entered :hello world
input is: hello world
Execution2:
Please enter: hello world
Input:
hello
output:
You entered :hello
input is not: hello world