第一次过程性考核-邹彤

1.Hello World!

https://gitee.com/ztsxxny/codes/kradjqwlb2gopvfn6ch8559

解析:简单的输出程序,注意语法即可。

2.求1到100的和

https://gitee.com/ztsxxny/codes/k8v0nxi3s9czow4mhre7q65

解析:利用while实现1到100的累加

public class Main{
  public static void main(String[] args){
    int i=1;
    int sum=0;
    while(i<=100) \\控制条件
    {
      sum=sum+i; \\累加,循环
      i++;
    }
    System.out.println("sum = "+sum);\\输出注意格式
  }
}

3.分段计算居民水费

https://gitee.com/ztsxxny/codes/qxlhzp0n1ag56dwv4brt764

解析:利用if实现控制分段计算水费

import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner scanner=new Scanner(System.in);\\从键盘上输入
    double x=scanner.nextDouble();
    if(x<=15){   \\用水量范围
      double y=4*x/3;
      System.out.printf("%.2f",y);  \\%.后的数字为保留小数位数
    }
    if(x>15){    \\用水量范围
      double y=2.5*x-17.5;
      System.out.printf("%.2f",y);
    }
  }
}

4.打印九九乘法表

https://gitee.com/ztsxxny/codes/g7d80pl4crehzmqsvf56w67

解析:利用for循环嵌套实现九九乘法表的输出

import java.util.Scanner;
public class Main
{
  public static void main(String []args)
  {
    Scanner reader=new Scanner(System.in);
    int N=reader.nextInt();
    for(int i=1;i<=N;i++)
    {
      for(int j=1;j<=i;j++)
      {
        if(j==i)  \\当两个乘数相等
        {
          System.out.printf("%d*%d=%-4d\n",j,i,i*j);  \\换行输出
        }
        else{
          System.out.printf("%d*%d=%-4d",j,i,i*j);  \\%-4d,空四格输出
        }
      }
    }
  }
}

学习内容 代码行 博客字
hello world 5 20
求1到100的和 12 90
分段计算居民水费 15 120
输出九九乘法表 22 200

猜你喜欢

转载自www.cnblogs.com/ztsxxny/p/9656867.html