java中String数组问题

发布网友 发布时间:2022-04-20 16:00

我来回答

1个回答

热心网友 时间:2023-07-06 11:42

告诉你算法
int num=0;
从es的后面开始,如果当前es的元素在ls中出现,ls中的当前元素和es[num++]交换,循环完es,结果就出来了

public class Test
{
public static void main(String[] args)
{
String stemp;

String[] ls = {"A","B","C","V","G","H","K","M","N","S","P","U","V","W","S"};
String [] es = {"B","K","S","U","N"};
int num=0;

for(int i=es.length-1;i>=0;i--)

for(int j=0;j<ls.length,j++)

{
if(ls[j].equals(es[i]))

{
stemp=ls[num];

ls[num++]=ls[j];

ls[j]=temp;

}

}
}
}

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com