How to do the inverse of the string in jsp?

advertisements

This is my demo.jsp code ,here i'm writing code as follow,result showing as No line found exception where as i executed the code in java class working fine.How can i execute the revers e of string in jsp page?

Scanner sc = new Scanner(System.in);
        System.out.println("Enter String :");
        String n = sc.nextLine();
        String rev = "";
        int len = n.length();
        for (int i = len - 1; i >= 0; i--) {
            rev = rev + n.charAt(i);
        }
        out.println("Reverse of Given String is :");
        out.println("" + rev);


Your current code works without errors . i guess the problem is you are passing the empty string as the input to nextLine method,

Try passing the values like this ,

Scanner sc = new Scanner(System.in);
        System.out.println("Enter String :");
        String n = sc.nextLine();
        String rev = "value";
        int len = n.length();
        for (int i = len - 1; i >= 0; i--) {
            rev = rev + n.charAt(i);
        }
        out.println("Reverse of Given String is :");
        out.println("" + rev)

Hope this helps !!