Java——for语句一些简单的应用
发布日期:2021-05-12 12:43:17 浏览次数:10 分类:精选文章

本文共 2679 字,大约阅读时间需要 8 分钟。

Java������for������������������������������������

Java���for���������������������������

for���������������������

for������ ���Java���������������������������������������������������������������������

for(���������1������������2������������3) {  
// ���������
}
  • ���������1������������������������������������������������
  • ���������2������������������������������������������������false������������������������true������������������3������������������������2���
  • ���������3���������������2���������������������������������������������������

for���������������������

  • ���������������1���������
  • ���������������2���������
    • ���������false������������������������������for������������������
    • ���������true������������������������
  • ������������������������������
  • ���������������3���������
  • ���������������������2���������������������2���3���
  • ������������������������for������������

    ���������������������������������������������������

    for (��������� ������������: ���������) {  
    // ���������
    }
    • ������������������������������������������������������������������
    • ������������������������������������������������������������������������
    • ���������������������������������������������

    Java������for���������1~100������

    ������������������for������������1���100���������

    ������������

    package for;  
    public class One {
    public static void main(String[] args) {
    int sum = 0;
    for (int i = 1; i <= 100; i++) {
    sum += i;
    }
    System.out.println("������������" + sum);
    }
    }

    ���for������������������������������

    ������������������for������������������������������������������������

    ������������

    package for;  
    public class Three {
    public static void main(String[] args) {
    int F[] = {7, 11, 30};
    for (int a : F) {
    System.out.println("���������������" + a);
    }
    }
    }

    Java������������������10���������������������������������������������

    ������������������for������������������������������������������������������������������

    ������������

    package for;  
    import java.text.DecimalFormat;
    import java.util.Scanner;
    public class Two {
    public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    DecimalFormat df = new java.text.DecimalFormat(".00");
    float score = 0, sum = 0, avg;
    for (int i = 1; i <= 10; i++) {
    System.out.println("������������" + i + "���������������������");
    score = sc.nextFloat();
    sum += score;
    sc.close();
    }
    avg = sum / 10;
    System.out.println("���������" + df.format(sum));
    System.out.println("������������" + df.format(avg));
    }
    }
    上一篇:Java——while语句简单的知识和应用
    下一篇:批改网如何解除老师设置的禁止复制粘贴

    发表评论

    最新留言

    哈哈,博客排版真的漂亮呢~
    [***.90.31.176]2025年04月28日 16时10分04秒