5-1循環(huán)是怎么寫(xiě)的
public class HelloWorld {
? ? public static void main(String[] args) {
? ? ? ??
? ? ? ? // 變量保存成績(jī)
? ? ? ? int score = 53;?
? ? ? ??
? ? ? ? // 變量保存加分次數(shù)
? ? ? ? int count = 0;
? ? ? ? //打印輸出加分前成績(jī)?
? ? ? ? ??
? ? ? ?System.out.println("加分前成績(jī):"+score);
? ? ? ??
? ? ? ? // 只要成績(jī)小于60,就循環(huán)執(zhí)行加分操作,并統(tǒng)計(jì)加分次數(shù)
? ? ? ? for(int i = 53; i <= 60 ; i++){
? ? ? ? System.out.println("加分后成績(jī):"+score++);
? ? ? ? ? ? ?System.out.println("共加了"+count++ +"次");?
? ? ? ? }
? ? ? ? //打印輸出加分后成績(jī),以及加分次數(shù)
? ? ?
? ? }
}
2017-07-11
public class HelloWorld {
??? public static void main(String[] args) {
??? ?int score=53;
??? ?int count=0;
??? ?System.out.println("加分前成績(jī)"+score);
??? ?for(;score<60;score++){
??? ??count++;
??? ?}
??? ?System.out.println("加分后成績(jī):"+score);
??? ?System.out.println("共加了"+count+"次!");
??? ?
??? }
}
???????
2017-07-21
2017-07-11
public class Demo1 {
public static void main(String[] args){
int score=53;
int count=0;
System.out.println("加分前的成績(jī):"+score);
while(score<=60){
score++;
count++;
}
System.out.println("加分后的成績(jī):"+score);
System.out.println("它加了"+count+"次!");
}
}
2017-07-11
? public static void main(String[] args) {
??? ?int score=53;
??? ?int count=0;
??? ?System.out.println("加分前成績(jī)"+score);
??? ?while(score<60){
? ? ? score++;
??? ??count++;
??? ?}
??? ?System.out.println("加分后成績(jī):"+score);
??? ?System.out.println("共加了"+count+"次!");
??? ?
??? }
}