package cn.com;//计算数组中元素出现的次数publicclassDemo{publicstaticvoidmain(String[] args){int[] array ={87,65,67,67,65,87};int sum =0;int x =0;for(int i =0; i < array.length; i++){for(int a =0; a < array.length; a++){if(array[a]== array[i]){if(i > a){
x =1;continue;}else{
sum++;}}}if(x ==1){
x =0;continue;}else{
System.out.println(array[i]+"出现了"+ sum +"次");
sum =0;
x =0;}}}}
利用while循环解决
package cn.com;//while解决计算数组中元素出现的次数publicclassDemo{publicstaticvoidmain(String[] args){int[] array ={87,65,67,65,87};int sum =0;int x =0;int i =0;while(i < array.length){int a =0;while(a < array.length){if(array[a]== array[i]){if(i > a){
x =1;
a++;continue;}else{
sum++;}}
a++;}if(x ==1){
i++;continue;}else{
System.out.println(array[i]+"出现了"+ sum +"次");
sum =0;
x =0;}
i++;}}}
利用do…while循环解决
package cn.com;//do...while解决计算数组中元素出现的次数publicclassDemo{publicstaticvoidmain(String[] args){int[] array ={87,65,67,65,87};int sum =0;int x =0;int i =0;do{int a =0;do{if(array[a]== array[i]){if(i > a){
x =1;
a++;continue;}else{
sum++;}}
a++;}while(a < array.length);if(x ==1){
i++;continue;}else{
System.out.println(array[i]+"出现了"+ sum +"次");
sum =0;
x =0;}
i++;}while(i < array.length);}}
计算数组中元素出现的次数利用for循环解决package cn.com;//计算数组中元素出现的次数public class Demo { public static void main(String[] args) { int[] array = { 87, 65, 67, 67, 65, 87 }; int sum = 0; int x = 0; for (int...