using java Working with char arrays Given a char array build
using java
Working with char arrays. Given a char array, build a method that will print the chars in the array out in reverse order. Call your class “Reverse3”, and store it in a file called “Reverse3.java”.
public static void main(….) {
char name[] = {‘S’, ‘t’, ‘e’, ‘v’, ‘e’ };
print out the name array.
reverse3(name); //will print out chars backwards
}
You build the Reverse3 class and the reverse3() method. Make sure to make the method static.
Solution
Reverse3.java
public class Reverse3 {
public static void main(String str[]) {
char name[] = {\'S\', \'t\', \'e\', \'v\', \'e\' };
reverse3(name); //will print out chars backwards
}
public static void reverse3(char name[]){
for(int i= name.length-1; i>=0; i--){
System.out.print(name[i]+\" \");
}
}
}
Output:
e v e t S
