How to use Scanner Class in Java | String Reverse | Palindrome String

What is Scanner Class in Java? 

Scanner Class in JAVA help us get the input from the users. 

This class is present in util.pkg We need to import this pkg in JAVA by using: 

import java.util.Scanner;

Practical Code:

public static void main(String[] args) {

System.out.println("Add your input values here");

Scanner SC = new Scanner(System.in); // Here System.in  >> takes the input from keyboard.


How can we check if the String is palindrome or not using the Scanner Class?


Code Base:

>>>>>

public static void main(String[] args) {

String rev= "";

Scanner SC = new Scanner(System.in);

System.out.println("Enter String to reverse here: ");

String S = SC.nextLine();

for (int i=S.length()-1; i>=0;i-- ) {

rev= rev + S.charAt(i); }

if (rev.contentEquals(S)) {

System.out.println("Yes");

}

else{System.out.println("NO");

    }

  }

}

<<<<<

Comments