Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
114 views
by Contributing Tester (92 points)

i have a progam to reverse simple string. It seems printing incorrect output and not the rev string.

public class RevString {
public static void main(String[] args) {
    
    String test = "Th";
    
    int lenght = test.length();
    
    System.out.println(test.charAt(lenght-1)+test.charAt(lenght-2));
    
    
}
}

output --

220

1 Answer

0 like 0 dislike
by

Do you want to try using 

System.out.println(test.charAt(lenght-1).toString()+test.charAt(lenght-2).toString());


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

1.4k questions

1.6k answers

866 comments

1.9k users

...