• Document


     1 /**
     2  * 需求分析:计算100以内的和,用while
     3  * @author chenyanlong
     4  * 日期:2017/10/14
     5  */
     6 package com.hp.test04;
     7 
     8 public class HS_Loop1 {
     9 
    10     public static void main(String[] args) {
    11         // TODO Auto-generated method stub
    12        int i=1,sum=0;
    13        
    14        while(i<=100){
    15            sum=sum+i;
    16            i++;
    17        }
    18        System.out.println("100以内的和:"+sum);
    19     }
    20 
    21 }
     1 /**
     2  * 需求分析:计算100以内的和,用while
     3  * @author chenyanlong
     4  * 日期:2017/10/14
     5  */
     6 package com.hp.test04;
     7 
     8 public class HS_Loop1 {
     9 
    10     public static void main(String[] args) {
    11         // TODO Auto-generated method stub
    12        int i=1,sum=0;
    13        
    14        while(i<=100){
    15            sum=sum+i;
    16            i++;
    17        }
    18        System.out.println("100以内的和:"+sum);
    19     }
    20 
    21 }
     1 /**
     2  * 需求分析:输入5门成绩求平均分
     3  * @author chenyanlong
     4  * 日期:2017/10/14
     5  */
     6 package com.hp.test04;
     7 
     8 import java.util.Scanner;
     9 
    10 public class HS_Loop3 {
    11 
    12     public static void main(String[] args) {
    13         // TODO Auto-generated method stub
    14         String name;
    15         double sum=0,score;
    16         double avg=0;
    17         System.out.println("请输入姓名:");
    18         
    19         Scanner input= new Scanner(System.in);
    20         name=input.next();
    21         //System.out.println(name);
    22         for(int i=1;i<=5;i++){
    23             System.out.print("请输入5门功课的第"+i+"门功课的成绩:");
    24             
    25             Scanner input2=new Scanner(System.in);
    26             score=input2.nextDouble();
    27             sum=sum+score;
    28         }
    29         avg=sum/5;
    30         System.out.println(name+"的平均分是:"+avg);
    31     }
    32 }
     1 /**
     2  * 需求分析:输入5门成绩求平均分,可以输入多个人
     3  * @author chenyanlong
     4  * 日期:2017/10/14
     5  */
     6 package com.hp.test04;
     7 
     8 import java.util.Scanner;
     9 
    10 public class HS_Loop4 {
    11 
    12     public static void main(String[] args) {
    13         // TODO Auto-generated method stub
    14         String letter=null;
    15         do{
    16             String name;
    17             double sum=0,score;
    18             double avg=0;
    19             System.out.println("请输入姓名:");
    20             
    21             Scanner input= new Scanner(System.in);
    22             name=input.next();
    23             //System.out.println(name);
    24             for(int i=1;i<=5;i++){
    25                 System.out.print("请输入5门功课的第"+i+"门功课的成绩:");
    26                 
    27                 Scanner input2=new Scanner(System.in);
    28                 score=input2.nextDouble();
    29                 sum=sum+score;
    30             }
    31             avg=sum/5;
    32             System.out.println(name+"的平均分是:"+avg);
    33             
    34             System.out.print("继续输出吗?(Y/N):");
    35             Scanner input3=new Scanner(System.in);
    36             letter=input3.next();
    37         }while(letter.equals("Y")||letter.equals("y"));
    38         System.out.println("录入完毕");
    39     }
    40 }
     1 /**
     2  * 需求分析:break的用法
     3  * @author chenyanlong
     4  * 日期:2017/10/14
     5  */
     6 package com.hp.test04;
     7 
     8 import java.util.Scanner;
     9 
    10 public class HS_Loop5 {
    11 
    12     public static void main(String[] args) {
    13         // TODO Auto-generated method stub
    14         for(int i=1;i<10;i++){
    15             if(i==5){
    16                 System.out.println("跳出一次");
    17                 continue;                
    18             }
    19             System.out.println("   "+i);
    20         }
    21     }
    22 }
     1 /**
     2  * 需求分析:break的用法
     3  * @author chenyanlong
     4  * 日期:2017/10/14
     5  */
     6 package com.hp.test04;
     7 
     8 import java.util.Scanner;
     9 
    10 public class HS_Loop6 {
    11 
    12     public static void main(String[] args) {
    13         // TODO Auto-generated method stub
    14         for(int i=1;i<10;i++){
    15             if(i==5){
    16                 System.out.println("循环提前结束");
    17                 break;                
    18             }
    19             System.out.println("   "+i);
    20         }
    21     }
    22 }
  • 相关阅读:
    oracle之check约束小结
    非归档模式下使用Rman进行备份和恢复
    R中,定义一个长度为0的向量
    R中,去掉dataframe中的NA行
    Oracle数据库的后备和恢复————关于检查点的一些知识
    关于oracle修复控制文件与数据文件不一致的问题----
    《SLAM机器人基础教程》第三章 单片机与STM32:GPIO实验及Keil软件使用WatchWindows进行Debug调试
    《SLAM导航机器人基础》第三章:单片机与STM32:单片机概述和Keil开发环境配置
    《SLAM导航机器人基础》第二章:C/C++编程(后)
    《SLAM导航机器人基础》第二章:C/C++编程(中)
  • 原文地址:https://www.cnblogs.com/chenyanlong/p/7668879.html
Copyright © 2020-2023  润新知