题目1
来源:互联网 发布:mac 局域网ip 编辑:程序博客网 时间:2024/06/14 08:34
知识点:
1、求素数 写一个flag,当flag为真时添加进list中
2、list.indexOf(元素) 表示元素第一次出现的位置
package Practice;import java.sql.SQLSyntaxErrorException;import java.util.*;public class Timu3 { public static void main(String[] args){//写一个代码求1-100内的素数 Scanner scan=new Scanner(System.in); int count=scan.nextInt(); int result=0; // boolean flag=false; List<Integer> list =new ArrayList<Integer>(); //for(int i=1,j=1;i<count&&j<i;i++,j++){ for (int i = 2; i <= count; i++) { boolean flag = true; for (int j = 2; j < i; j++) { if ( i % j == 0) { flag = false; break; } } if(flag) {list.add(i);} } for(ListIterator<Integer> it=list.listIterator();it.hasNext();){ if(list.indexOf(count-list.get(0))==-1){ list.remove(0); } else{ if(list.size()!=0){ result++; // list.remove(list.indexOf(count-list.get(0))); list.remove(0); }} } System.out.println(result); } }
阅读全文
0 0
- 题目1
- 题目1
- 题目1
- 题目1
- 题目1
- 题目1
- 题目1
- 题目1
- 题目1 : Performance Log--微软题目
- Java面试题目(1)
- 笔试题目1
- moto面试题目1
- 面试题目1
- 常见面试题目1
- java面试题目1
- 数字电路笔试题目1
- JAVA经典题目1
- sql经典题目(1)
- 递归
- HttpClients 工具类
- HDFS只支持文件append操作, 而依赖HDFS的HBase如何完成增删改查功能
- SQL---基础语句select
- C考卷编译
- 题目1
- HDU
- C++类方法实现简单的贪吃蛇游戏
- 关联规则之Apriori算法
- mysql
- 腾讯笔试题 2 有趣的数字
- The server time zone value '�й���ʱ��' is unrecognized or represents more than one time zone. You m
- Codeforces-429-2-B Godsend
- ###Jsp+Servlet购物商城day02.2:首页显示 最新和热门商品