62,621
社区成员
发帖
与我相关
我的任务
分享
import java.util.HashMap;
import java.util.Map;
public class Test{
public static void main(String[] args) {
int[] a = { 1, 3, 6, 7, 7, 7, 9, 9, 9, 6, 5, 5, 3 };
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
for (int i = 0; i < a.length; i++) {
int key = a[i];
Integer v = map.get(key);
map.put(key, v == null ? 1 : v + 1);
}
int tempKey = 0;
int tempValue = 0;
for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
if (entry.getValue() > tempValue) {
tempKey = entry.getKey();
tempValue = entry.getValue();
}
}
System.out.println("[" + tempKey + "," + tempValue + "]");
}
}
import java.util.HashMap;
import java.util.Map;
public class Test1 {
public static void main(String[] args) {
int[] arr={1,3,6,7,7,7,9,9,9,6,5,5,0,3};
Map<Integer, Integer> map=new HashMap<Integer, Integer>();
for(int temp:arr)
{
if(map.containsKey(temp)){
int m=(Integer)map.get(temp)+1;
map.put(temp,m);
}
else
{
map.put(temp, 1);
}
}
int n=0;
String strArr="";
for(Map.Entry<Integer, Integer> entry : map.entrySet())
{
if(entry.getValue()>n){
n=entry.getValue();
strArr=String.valueOf(entry.getKey());
}
else if (entry.getValue()==n)
{
strArr=strArr+","+String.valueOf(entry.getKey());
}
}
int maxNum=0;
for(String s:strArr.split(",")){
if(Integer.valueOf(s)>maxNum)
{
maxNum=Integer.valueOf(s);
}
}
System.out.println("出现次数最多且最大的数是: "+maxNum);
System.out.println("出现次数是: "+n);
}
}
import java.util.*;
public class ReverseTest
{
public static void main(String[] args)
{
String str = "abcdef";
System.out.println("顺序前:" + str);
char[] str_char = str.toCharArray();
int len = str_char.length - 1;
for(int i = 0;i <= len/2 ; i++)
{
char temp = str_char[i];
str_char[i] = str_char[len - i];
str_char[len - i] = temp;
}
str = new String(str_char);
System.out.println("逆序后:" + str);
}
}
public class GetMax
{
public static void main(String[] args)
{
int[] source = {1,3,6,7,7,7,9,9,9,6,5,5,3,1,1};
int[] count = new int[source.length];
for(int i = 0;i < source.length;i++)
{
count[source[i]]++;
}
int max = count[0];
int sub = 0;
for(int i = 0;i < count.length;i++)
{
if(count[i] >= max)
{
max = count[i];
sub = i;
}
}
System.out.println("下标是: " + sub + "出现次数是: " + count[sub]);
}
}
<script language="javascript">
function a(){
var str='abc',sOut='';
var arr = str.split('');
for(var i = arr.length-1;i>=0;i--){
sOut+=arr[i];
}
alert(sOut);
}
</script>