java 面试每日一题7
2024-09-16 20:38:21
题目:判断101-200之间有多少个素数,并输出所有素数。
1.程序分析:判断素数的方法:用一个数分别去除2到sqrt(这个数),如果能被整除,
则表明此数不是素数,反之是素数。
public class test07 {
public static void main(String[] args) throws NumberFormatException, IOException{
int num=1;
for(int j=101;j<201;j++){
boolean flag=false;
for(int i=2;i<j;i++){
int res=j%i;
if(res==0){
flag=false;
break;
}else{
flag=true;
}
}
if(flag==true){
System.out.println(num+++"zz"+j);}
} } }
public class test07 {
public static void main(String[] args) throws NumberFormatException, IOException{
int num=1;
for(int j=101;j<201;j++){
boolean flag=false;
for(int i=2;i<=Math.sqrt(j);i++){
int res=j%i;
if(res==0){
flag=false;
break;
}else{
flag=true;
}
}
if(flag==true){
System.out.println(num+++"zz"+j);}
} } }
最新文章
- sublime text3同时编辑多行
- OC基础--self关键字
- javamail 发送附件
- MySQL: LEAVE Statement
- C和指针 第一章 字符串处理程序
- mac android studio 编译时报Class JavaLaunchHelper is implemented in both
- web.py+mysql插入中文提示query = query.encode(charset) UnicodeEncodeError: &#39;latin-1&#39; codec can&#39;t encode characters in position 86-100
- C++库研究笔记——操作符重载实现类型转换&这样做的意义
- 08_android入门_android-async-http开源项目介绍及用法
- Fiddler 模拟post 提交
- leetcode_Search in Rotated Sorted Array II
- poj 2299 Ultra-QuickSort 逆序对模版题
- Docker Swarm集群
- java宜立方商城项目
- 2018 ACM-ICPC, Syrian Collegiate Programming Contest
- C# Invoke方法
- [UI] 05 - Bootstrap: built-in components
- 关于linux-Centos 7下mysql 5.7.9的rpm包的安装方式
- Hadoop概念学习系列之谈hadoop/spark里分别是如何实现容错性?(四十二)
- ReactNative WebView组件详解
热门文章
- iOS获取运营商的相关信息
- ios - 图片自动轮播定时器(NSTimer)以及消息循环模式简介
- my ambition
- Java-NIO-Selector
- Leetcode: Count Numbers with Unique Digits
- JaveScript——简介、语法
- 最大权闭合图最大获益(把边抽象为点)HDU3879
- hduoj 4708 Rotation Lock Puzzle 2013 ACM/ICPC Asia Regional Online —— Warmup
- [转] linux中pam模块
- java中时间的比较