# 用java实现

...全文
956 9 打赏 收藏 转发到动态 举报

9 条回复

an_liu 2018-05-12
• 打赏
• 举报

``````public static void main(String[] args) {
int i = 12578;
int count=1;
//为了方便遍历
HashMap<Integer,Integer> map = new HashMap<>();

// 数数
while(i != 98752) {
String s ="";
s+=i;

// 正则: 不能重复,不能是0346 ,长度等于5
if(s.matches("(?!\\d*(\\d)\\d*\\1\\d*)[^0346]{5}")) {
if(Integer.parseInt(s)%75 == 0) {
int num = Integer.parseInt(s);
map.put(count, num);
count++;
}
}
i++;
}

//遍历
for (Integer key : map.keySet()) {
System.out.println("第"+key+"个是"+map.get(key));
}

}
}``````
an_liu 2018-05-12
• 打赏
• 举报

``````    public static void main(String[] args) {
int i = 12578;
int count=1;
//为了方便遍历
HashMap<Integer,Integer> map = new HashMap<>();

// 数数
while(i != 98752) {
String s ="";
s+=i;

// 正则: 不能重复,不能是0346 ,长度等于5
if(s.matches("(?!\\d*(\\d)\\d*\\1\\d*)[^0346]{5}")) {
if(Integer.parseInt(s)%75 == 0) {
int num = Integer.parseInt(s);
map.put(count, num);
count++;
}
}
i++;
}

//遍历
for (Integer key : map.keySet()) {
System.out.println("第"+key+"个是"+map.get(key));
}

}``````

• 打赏
• 举报

[quote=引用 3 楼 lynmison 的回复:] 1、五位数范围是 10000~99999，可以算出循环的范围 14~1333 2、循环算出能被75整除数 3、用正则过滤不符合要求结果和符合要求结果
``````
private static boolean matched(String content){
if (content.contains("0")) return false;

String regEx = "(?!\\d*(\\d)\\d*\\1\\d*)\\d{5}";
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(content);
return m.find();
}

public static void main(String[] args){
int l = 10000/75;
int h = 99999/75;
int result;
for(int i=l; i<=h; i++){
result = i*75;
String tmp = String.format("%d", result);
if (matched(tmp)) System.out.println(tmp+":matched");
else System.out.println(tmp+":not matched");
}
}
``````

• 打赏
• 举报

qq_22880091 2018-05-11
• 打赏
• 举报

import java.util.ArrayList; import java.util.List; public class Test { public static void main(String[] args) { String[] numArr = new String[]{"1","2","5","7","8","9"}; int value = 75; List<Integer> numList = getAllNumList(numArr,value); System.out.println(numList); } private static List<Integer> getAllNumList(String[] numArr,int value) { List<Integer> numList = new ArrayList<Integer>(); //六个数字里面取五个 List<List<String>> newNumArr = getNewNumArr(numArr); List<String> sl = null; for(List<String> list : newNumArr){ sl = new ArrayList<String>(); getAllStr(list, new StringBuffer(), sl); for(String s : sl){ if(Integer.valueOf(s)%value==0) numList.add(Integer.valueOf(s)); } } return numList; } private static List<List<String>> getNewNumArr(String[] numArr) { List<String> numList = new ArrayList<String>(); for(String num : numArr){ numList.add(num); } List<List<String>> numlistAll = new ArrayList<List<String>>(); List<String> numListForSave = null; for(String num : numArr){ numListForSave = clone(numList); numListForSave.remove(num); numlistAll.add(numListForSave); } return numlistAll; } private static List<String> clone(List<String> numList) { List<String> cloneList = new ArrayList<String>(); if(numList!=null && numList.size()>0) for(String s : numList) cloneList.add(s); return cloneList; } private static void getAllStr(List<String> str, StringBuffer sb,List<String> sl) { if(str.size()>0){ List<String> clone = null; for(String s : str){ sb = new StringBuffer(sb); sb.append(s); clone = clone(str); clone.remove(s); getAllStr(clone, sb,sl); sb = new StringBuffer(sb.substring(0, sb.length()-1)); } }else{ sl.add(sb.toString()); } } }
• 打赏
• 举报

1、五位数范围是 10000~99999，可以算出循环的范围 14~1333 2、循环算出能被75整除数 3、用正则过滤不符合要求结果和符合要求结果
``````
private static boolean matched(String content){
if (content.contains("0")) return false;

String regEx = "(?!\\d*(\\d)\\d*\\1\\d*)\\d{5}";
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(content);
return m.find();
}

public static void main(String[] args){
int l = 10000/75;
int h = 99999/75;
int result;
for(int i=l; i<=h; i++){
result = i*75;
String tmp = String.format("%d", result);
if (matched(tmp)) System.out.println(tmp+":matched");
else System.out.println(tmp+":not matched");
}
}
``````

• 打赏
• 举报

1、五位数范围是 10000~99999，可以算出循环的范围 14~1333 2、循环算出能被75整除数 3、用正则过滤不符合要求结果和符合要求结果
``````
private static boolean matched(String content){
if (content.contains("0")) return false;

String regEx = "(?!\\d*(\\d)\\d*\\1\\d*)\\d{5}";
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(content);
return m.find();
}

public static void main(String[] args){
int l = 10000/75;
int h = 99999/75;
int result;
for(int i=l; i<=h; i++){
result = i*75;
String tmp = String.format("%d", result);
if (matched(tmp)) System.out.println(tmp+":matched");
else System.out.println(tmp+":not matched");
}
}
``````
java-小学生 2018-05-11
• 打赏
• 举报

public static void main(String[] args) { //125789组成一个五位数至多用一次能被75整除有几个？ List<Integer> list = new ArrayList<>(); List<Integer> results = new ArrayList<>(); list.add(1); list.add(2); list.add(5); list.add(7); list.add(8); list.add(9); int count = 0; while (true) { Collections.shuffle(list); StringBuffer sb = new StringBuffer(); for (int i = 0; i < list.size() - 1; i++) { sb.append(list.get(i)); } String s = sb.toString(); int result = Integer.parseInt(s); if ((result % 75) == 0 && !(results.contains(result))) { count++; results.add(result); System.out.println(count + "......." + result); } } } 控制台： 1.......92175 2.......21975 3.......91275 4.......81975 5.......19275 6.......91875 7.......29175 8.......19725 9.......97125 10.......17925 11.......71925 12.......19875 13.......12975 14.......91725 15.......98175 16.......18975 17.......79125 18.......89175 做的不好，初步实现
• 打赏
• 举报

50,336

javaspring bootspring cloud 技术论坛（原bbs）

• 近7日
• 近30日
• 至今