美文网首页
使用for语句与if语句

使用for语句与if语句

作者: 哈迪斯Java | 来源:发表于2021-10-13 20:12 被阅读0次
    image.png

    ================================
    package HspLearning;

    public class For3 {
    public static void main(String[] args) {
    int start = 1;
    int end = 100;
    int count = 0;
    int sum = 0;
    for (int i = start;i<= end;i++){
    if(i%9 == 0){
    System.out.println("i="+i);
    count++;
    sum +=i;
    }
    }
    System.out.println("能被9整除的个数为:"+count);
    System.out.println(sum);
    }
    }

    ===========


    image.png

    ===========
    package HspLearning;

    public class For3 {
    public static void main(String[] args) {
    int start = 1;
    int end = 100;
    int t = 9;
    int count = 0;
    int sum = 0;
    for (int i = start;i<= end;i++){
    if(i % t == 0){
    System.out.println("i="+i);
    count++;
    sum +=i;
    }
    }
    System.out.println("能被9整除的个数为:"+count);
    System.out.println(sum);
    }
    }

    相关文章

      网友评论

          本文标题:使用for语句与if语句

          本文链接:https://www.haomeiwen.com/subject/nvyeoltx.html