4th Sep 2017, 3:17 AM
rahul mishra
rahul mishra - avatar
5 Answers
+ 15
import java.io.*; import java.util.*; public class Program { public static void main(String[]args) { Scanner sc = new Scanner(System.in); System.out.println("please enter your name :-"); String name = sc.nextLine(); String new_name = ""; //reversing the String using for loop. for(int i = name.length() - 1; i>=0; i--) { new_name += name.charAt(i); } System.out.println("reverse String is :-\n "+ new_name); } }
4th Sep 2017, 4:19 AM
Hatsy Rei
Hatsy Rei - avatar
+ 5
import java.util.Scanner; public class Program { public static void main(String[]args) { Scanner sc = new Scanner(System.in); System.out.println("please enter your name :-"); char[] name = sc.nextLine().toCharArray(); String new_name = ""; //reversing the String using for loop. for(int i=name.length-1;i>=0;i--) { new_name += name[i]; } System.out.println("reverse String is :-\n "+ new_name); } }
4th Sep 2017, 3:56 AM
ChaoticDawg
ChaoticDawg - avatar
+ 3
I write it in comments bir simply here 1-declarations should be made outside loop 2-after calling a method use () in your case name.length (); 3. for using a string as like as array you need a method as like as length () in your case you should use name.charAt (i);
4th Sep 2017, 3:51 AM
Melih Melik Sonmez
Melih Melik Sonmez - avatar
+ 2
it is much better that share your code from codeplayground by link
4th Sep 2017, 3:21 AM
Melih Melik Sonmez
Melih Melik Sonmez - avatar
4th Sep 2017, 3:24 AM
rahul mishra
rahul mishra - avatar