java - Where am I wrong in this program? -
this program reverse array. now, how create function print reversed array?
public class question1 { public static void main( string [] args ) { char[] myname = { 'h', 'a', 's', 'h', 'i', 'm' }; reverse(myname); } public static void reverse(char[] array) { (int = 5; >= 0; i--) { char reversearray = array[i]; } } }
you try using charat method:
class reversestring { public static void main(string args[]) { string original, reverse = ""; scanner in = new scanner(system.in); system.out.println("enter string reverse"); original = in.nextline(); int length = original.length(); ( int = length - 1 ; >= 0 ; i-- ) reverse = reverse + original.charat(i); system.out.println("reverse of entered string is: "+reverse); } }
Comments
Post a Comment