Check entered String is magic string or not


Write a Program in Java to enter a string and check whether it is magic string or not?

In this post, we will see whether the entered string is a magic string or not.

The Scanner class used to get user input, and it is found in the java.util package.

To use the Scanner class, create as an object of the class and use any of the available methods found in the Scanner class documentation.

Example:  Check entered String is a magic string or not

    import java.util.Scanner;

    public class UserInputString {

        public static void main(String args[]) {

              Scanner in = new Scanner(System.in);

             System.out.print("EnterString: ");

             String name= in.nextLine();

             String str = "magic";

             str.trim();

          if (name.equals(str)){

                 System.out.println("Entered String is magic string");

            }           else {

                   System.out.println("Entered String is not magic string");

                }

             in.close();

         }

    }

Output:
Enter the String: Kerla
Entered String is magic string

Eclipse Code:





Useful Programs:

Java Program to Multiply Two Number

Java Program to Check Even or Odd number

Java Program to check whether input character is vowel or consonant

Java Program to Check Even or Odd number




Previous
Next Post »