How can I get a char array in reverse order?

后端 未结 10 2574
情深已故
情深已故 2020-12-18 16:23

my assignment question is like that

Write a program which prints the letters in a char array in reverse order using

void printReverse(char         


        
10条回答
  •  孤城傲影
    2020-12-18 16:38

    I believe what you wrote is the signature of the method you have to create.

    public void printReverse(char[] letters, int size){
       //code here
    }
    

    You would have to iterate the array and print what it contains backwards. Use a reverse "for loop" to go through each item in "letters". I'll let you combine these yourself as it's an assignment. Here's an example of a for loop:

    for (int i = array.length-1; i >= 0 ; i--){
        System.out.print(array[i]);
    }
    

提交回复
热议问题