当前位置:网站首页>Daily code 300 lines learning notes day 9
Daily code 300 lines learning notes day 9
2022-07-06 15:03:00 【Leeyz_ one】
1. Yes while Loop for basic implementation
This section is relatively simple , So run the code directly
Code segment :
package demo3;
public class While {
/**
*********************
* The entrance of the program.
*
* @param args Not used now.
*********************
*/
public static void main(String args[]) {
whileStatementTest();
}// Of main
public static void whileStatementTest() {
int tempMax = 100;
int tempValue = 0;
int tempSum = 0;
// Approach 1.
while (tempSum <= tempMax) {
tempValue++;
tempSum += tempValue;
System.out.println("tempValue = " + tempValue + ", tempSum = " + tempSum);
} // Of while
tempSum -= tempValue;
System.out.println("The sum not exceeding " + tempMax + " is: " + tempSum);
// Approach 2.
System.out.println("\r\nAlternative approach.");
tempValue = 0;
tempSum = 0;
while (true) {
tempValue++;
tempSum += tempValue;
System.out.println("tempValue = " + tempValue + ", tempSum = " + tempSum);
if (tempMax < tempSum) {
break;
} // Of if
} // Of while
tempSum -= tempValue;
System.out.println("The sum not exceeding " + tempMax + " is: " + tempSum);
}// Of whileStatementTest
}//Of While
Running results :
2. summary
Like the comments on the eighth line and the previously learned code , Why do you often give one in that position args not used now Notes of ?
边栏推荐
- 函数:用牛顿迭代法求方程的根
- ES全文索引
- STC-B学习板蜂鸣器播放音乐
- Statistics, 8th Edition, Jia Junping, Chapter 6 Summary of knowledge points of statistics and sampling distribution and answers to exercises after class
- 【指针】查找最大的字符串
- 数字电路基础(三)编码器和译码器
- Function: find the root of the equation by Newton iterative method
- [oiclass] share prizes
- Global and Chinese markets of electronic grade hexafluorobutadiene (C4F6) 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese market of RF shielding room 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢
Software testing interview summary - common interview questions
Statistics 8th Edition Jia Junping Chapter 3 after class exercises and answer summary
四元数---基本概念(转载)
STC-B学习板蜂鸣器播放音乐2.0
CSAPP家庭作業答案7 8 9章
Database monitoring SQL execution
Fundamentals of digital circuits (II) logic algebra
How to learn automated testing in 2022? This article tells you
5 minutes to master machine learning iris logical regression classification
Stc-b learning board buzzer plays music 2.0
随机推荐
Global and Chinese markets of electronic grade hexafluorobutadiene (C4F6) 2022-2028: Research Report on technology, participants, trends, market size and share
[oiclass] share prizes
What level do 18K test engineers want? Take a look at the interview experience of a 26 year old test engineer
Numpy快速上手指南
Pointeurs: maximum, minimum et moyenne
数字电路基础(五)算术运算电路
Global and Chinese market of pinhole glossmeter 2022-2028: Research Report on technology, participants, trends, market size and share
[oiclass] maximum formula
Zhejiang University Edition "C language programming experiment and exercise guide (3rd Edition)" topic set
刷视频的功夫,不如看看这些面试题你掌握了没有,慢慢积累月入过万不是梦。
指针 --按字符串相反次序输出其中的所有字符
函数:用牛顿迭代法求方程的根
How to solve the poor sound quality of Vos?
Mysql的事务是什么?什么是脏读,什么是幻读?不可重复读?
[pointer] find the value of the largest element in the two-dimensional array
数字电路基础(四) 数据分配器、数据选择器和数值比较器
Statistics 8th Edition Jia Junping Chapter 7 Summary of knowledge points and answers to exercises after class
函数:求1-1/2+1/3-1/4+1/5-1/6+1/7-…+1/n
Function: find 1-1/2+1/3-1/4+1/5-1/6+1/7-... +1/n
【指针】删除字符串s中的所有空格