当前位置:网站首页>Day009 circular structure (exercise)
Day009 circular structure (exercise)
2022-07-21 19:29:00 【Mo Nian】
seek 100 All prime numbers within
( prime number : One is greater than 1 The natural number of , except 1 And it itself , Cannot be divided by other natural numbers )
package cn.bdqn.demo03;
public class Practice {
public static void main(String[] args) {
/*
* seek 100 All prime numbers within ( prime number : One is greater than 1 The natural number of , except 1 And it itself , Cannot be divided by other natural numbers )
*/
// Initial value
int i = 2;
while (i <= 100) {
boolean flag = true;
for(int j = 2; j < i; j++) {
if (i % j == 0) {
flag = false;
break;
}
}
if (flag) {
System.out.println(i);
}
i++;
}
}
}
Write a method , This method implements output 100-999 Between the number of daffodils .
package cn.bdqn.demo03;
public class Practice02 {
public static void main(String[] args) {
// Write a method , This method implements output 100-999 Between the number of daffodils .
int i= 100;
while(i<=999){
int a = i%10;
int b = i/10%10;
int c = i/100%10;
if(a*a*a+b*b*b+c*c*c==i){
System.out.println(i);
}
i++;
}
}
}
Find out 1-1/2+1/3-1/4…..1/100 And
package cn.bdqn.demo03;
public class Practice05 {
public static void main(String[] args) {
// Find out 1-1/2+1/3-1/4…..-1/100 And
int i = 1;
double sum = 0;
while (i <= 100) {
double a = -(1.0 / i);// i As denominator
if (i % 2 == 0) {
a = -(1.0 / i);
} else {
a = 1.0 / i;
}
sum += a;
i++;
}
System.out.println(sum);
}
}
Output the multiplication table
package cn.bdqn.demo03;
public class Practice11 {
public static void main(String[] args) {
// Output the multiplication table
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= 9; j++) {
if (j <= i) { // When i=1 when ,j=1, Meet the conditions , Execute output at this time , After execution j Self adding ,(j=2)>(i=1), Not meeting the conditions , Jump out of ;
// here i Self adding ,i=2, Enter again j Of for loop , here 1<2 Meet the conditions , Execution output 1*2=2, After execution j Self adding ,
//j=2, Satisfy j<=i, Execution output 2*2=4, After execution j Self adding ,j=3, here j<=i Don't set up , Out of the loop ; By analogy
System.out.print(j + "*" + i + "=" + (j * i) + " ");
//j==i Change the line , Realize the format of multiplication table
if (j == i) {
System.out.println(" ");
}
}
}
}
}
}
边栏推荐
猜你喜欢
Introduction to ESP privilege isolation mechanism
Detailed explanation of at mode principle of Seata (3)
载二氢丹参酮Ⅰ白蛋白纳米粒/去甲斑蝥素白蛋白纳米粒/伏立康唑白蛋白纳米粒的制备研究
Clickhouse in-depth disclosure
Penetration test - Application of file containing vulnerabilities and PHP pseudo protocol
Filter listener
The first lesson of programmers is "Hello word". Do you know the first lesson of network engineering?
SAP smartforms 打印失败 消息类型:SSFCOMPOSER 消息号:601 (货币和数字字段设置参考及格式)
h5在微信内自定义分享遇到的坑
分布式.高并发概念和设计目标
随机推荐
L1-003 个位数统计
寻找单身狗--重复两次数字中寻找单个数字
Metahuman Face材质球总结
Software testing interview question: talk about your understanding of the two strategies of top-down integration and bottom-up integration in integration testing, and talk about their respective advan
Distributed Capacity evaluation
QT(37)-mosquitto-MQTT客户端
Sql优化(九):分页语句优化
C what are the output points of DSP core resample of digital signal processing toolkit
程序员第一课“hello word”,你知道网工第一课吗?
h5在微信内自定义分享遇到的坑
MYSQL08_ Overview of sub query, single row, multi row, related sub query
hcip第二天实验
【LeetCode】1260. 2D mesh migration
Arduino I2C for tca9548a response scanner
Use the mogdb operator to deploy the mogdb cluster (mogdb stack) on kubernetes
Distributed What index is high concurrency
SAP IDOC教程:定义,结构,类型,格式和表格-019
蚓激酶白蛋白纳米粒/红细胞膜定向包裹血红蛋白-白蛋白纳米粒的研究制备
Recommended collection | practical operation, data console selection example
toast_ tuple_ Question of threshold