当前位置:网站首页>Li Kou brush question diary /day4/6.26
Li Kou brush question diary /day4/6.26
2022-07-04 18:35:00 【Bobo toilet cleaning spirit】
Novice Village
Sunrise Sunset , There is always dawn
VScode function java project
Create a new window
CTRL+SHIFT+P, Enter... In the pop-up window create java, choice No build tools
Select a folder to store java Project code
Set project name
You can run java Code
while loop
do while loop
do{
Code block
}while( Boolean expression );do while Loop at least once , Because execute first do sentence , Then execute the judgment statement while, So execute the code block content at least once .
while loop
while( expression ){
Code block ;
// Jump out of while Circular approach
if(){
break
}
}while(1)、while(2)、while(3) Both indicate that the condition is true , That is to say, not 0 The numbers of all mean true .
while If the expression of the loop is not satisfied , Do not execute once .
Self incrementing sign i++ and ++i
i++ First operation , One more
++i Yes, add one first , Re operation
Java in i=i++ and i++

In the above code , The last output i The value of is always 0,
because i First assign to i by 0, After one execution ,i The value of is 0, Proceed again i=i++, The assignment operation has been assigning i=0.
Modify the code

The above code can realize i A change in the value of ,while Statement executed n Time ,i The value is n
Example

Their thinking : First define the number of operations i, Create a while loop , Judge num Is it even , If yes num=num/2, No num=num-1.i++, Record the number of executions , Last return i
class Solution {
public int numberOfSteps(int num) {
int i=0;
while(num != 0){
if(num % 2 == 0){
num=num/2;
}
else{
num=num-1;
}
i++;
}
return i;
}
}
边栏推荐
- You should know something about ci/cd
- Weima, which is going to be listed, still can't give Baidu confidence
- [system disk back to U disk] record the operation of system disk back to U disk
- 爬虫初级学习
- 力扣刷題日記/day6/6.28
- 通过事件绑定实现动画效果
- 曾经的“彩电大王”,退市前卖猪肉
- 五千字讲清楚团队自组织建设 | Liga 妙谈
- 力扣刷题日记/day3/2022.6.25
- With the stock price plummeting and the market value shrinking, Naixue launched a virtual stock, which was deeply in dispute
猜你喜欢

激进技术派 vs 项目保守派的微服务架构之争

Li Kou brush question diary /day5/2022.6.27

90后开始攒钱植发,又一个IPO来了

【Hot100】32. Longest valid bracket

Li Kou brush question diary /day8/7.1

Unity 制作旋转门 推拉门 柜门 抽屉 点击自动开门效果 开关门自动播放音效 (附带编辑器扩展代码)

.NET ORM框架HiSql实战-第二章-使用Hisql实现菜单管理(增删改查)

ISO27001认证办理流程及2022年补贴政策汇总

Tutorial on the use of Huawei cloud modelarts (with detailed illustrations)

华为云ModelArts的使用教程(附详细图解)
随机推荐
DB-Engines 2022年7月数据库排行榜:Microsoft SQL Server 大涨,Oracle 大跌
Li Kou brush question diary /day7/2022.6.29
12 - explore the underlying principles of IOS | runtime [isa details, class structure, method cache | t]
. Net ORM framework hisql practice - Chapter 2 - using hisql to realize menu management (add, delete, modify and check)
Thawte通配符SSL证书提供的类型有哪些
未来几年中,软件测试的几大趋势是什么?
使用3DMAX制作一枚手雷
明星开店,退,退,退
[211] go handles the detailed documents of Excel library
[go language question brushing chapter] go conclusion chapter | introduction to functions, structures, interfaces, and errors
Clever use of curl command
Nature Microbiology | 可感染阿斯加德古菌的六种深海沉积物中的病毒基因组
力扣刷题日记/day2/2022.6.24
表情包坑惨职场人
Li Kou brush question diary /day6/6.28
LD_ LIBRARY_ Path environment variable setting
Li Kou brush question diary /day8/7.1
怎么开户才是安全的,
Stars open stores, return, return, return
Achieve animation effect through event binding