-2

public static void main(String[] args) {

    String firstName = "";
    double age =0;    
    String surname ="";
    String password ="";

   Scanner scan = new Scanner (System.in);

   System.out.println("Please enter your first name:");
   firstName= scan.nextLine();

   System.out.println("Please enter your age:");
   age=scan.nextDouble();

   System.out.println("Please enter your surname:");
   surname= scan.nextLine();

   System.out.println("Please enter your password:");
   password=scan.nextLine();

}

Do i create another variable for surnameBackwards?

Niamh
  • 1
  • 1
  • 1
    You can use StringUtils.reverse (https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/StringUtils.html) over surname. You can create a new String surnameBackwards to receive the reversed value and the rest of the password as you wish. – pringi Dec 14 '16 at 13:40
  • Does this answer your question? [Reverse a string in Java](https://stackoverflow.com/questions/7569335/reverse-a-string-in-java) – pringi Mar 04 '22 at 21:20

1 Answers1

0

Something like this:

String surnameBackwards = StringUtils.reverse(surname) + "*" + age + "*" + StringUtils.reverse(firstName)
pringi
  • 3,987
  • 5
  • 35
  • 45