我怎么能烧焦以相反的顺序排列? [英] How can I char array in reverse order?

查看:105
本文介绍了我怎么能烧焦以相反的顺序排列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我分配的问题是这样的。

编写一个程序,用它打印在字符数组中倒序字母

 无效printReverse(字符字母[],INT大小);

例如,如果阵列包含{'C','s'的,'C','2','6','1'}的输出应为162csc

我继电器试图解决,但我不明白这是什么意思!
    无效printReverse(字符字母[],INT大小);

所以我需要帮助乌拉圭回合知道我必须做的这出...

THX的家伙,我不喜欢这个,但那里调用方法printReverse到主法的问题!!

 进口java.util.Arrays中;
进口java.util.Collections中;公共类搜索{公共静态无效的主要(字串[] args){的char [] =字母{'E','V','O','L','4'};
printReverse();}公共无效printReverse(的char []信函,INT大小){的for(int i = letters.length-1; ​​I> = 0; I - ){
System.out.print(字母[I]);
}
}}


解决方案

我相信你写的是你要创建的方法的签名。

 公共无效printReverse(的char []信函,INT大小){
   // code在这里
}

您将不得不遍历数组并打印它包含什么倒退。使用反向循环要经过的每个项目中的信。我会告诉你这些结合自己因为它是一个任务。下面是一个for循环的例子:

 的for(int i = array.length-1; ​​I> = 0; I  - ){
    System.out.print(数组[我]);
}

my assignment question is like that

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

void printReverse(char letters[], int size);

For example, if the array contains {'c', 's', 'c', '2', '6', '1'} the output should be "162csc".

I relay tried to solve it but I don't understand what this means !! void printReverse(char letters[], int size);

so I need ur help to know what I have to do to figure this out ...

thx guys , I did like this but there's problem with calling the method "printReverse" into main method !!..

import java.util.Arrays;
import java.util.Collections;

public class search {

public static void main(String[] args) {          

char[] letters = {'e', 'v', 'o', 'l', '4'};
printReverse();

}

public void printReverse(char[] letters, int size){

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

}

解决方案

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]);
}

这篇关于我怎么能烧焦以相反的顺序排列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆