JAVA语言程序设计课后习题----第一单元解析(仅供参考)

1  本题是水题,基本的输出语句

1 public class test {
2     public static void main(String[] args) {
3 //      相邻的两个 "" 要用 + 相连
4 //        \t相当于tab键
5         System.out.println("xxx"+"\t"+"18岁");
6     }
7 }

2  本题可以用一个for循环来实现循环十次即可

 1 public class test {
 2     public static void main(String[] args) {
 3         int sum=0;
 4 //        定义一个变量sum来接收每次相加的结果
 5 //        for循环10次,从1开始每次都把值与sum相加
 6         for (int i = 1; i <=10 ; i++) {
 7             sum += i;
 8         }
 9         System.out.println("1+2+...+10="+sum);
10     }
11 }

3  本题考的就是圆的周长、面积公式的运用

 1 public class test {
 2     public static void main(String[] args) {
 3 //        PI的用法
 4        double area,az,r=5.5;
 5        area=Math.PI*r*r;
 6        az=Math.PI*r*2;
 7         System.out.println("园的面积为:"+area);
 8         System.out.println("园的周长为:"+az);
 9     }
10 }

4  本题考的是双重for循环,一个循环控制行数,一个循环控制每行输出几个*

 1 public class test {
 2     public static void main(String[] args) {
 3        /*
 4        * 第一层for循环循环5次代表着有五行
 5        * 第二个for循环代表着每次循环几次*/ 
 6         for (int i = 1; i <=5 ; i++) {
 7             for (int j = 1; j <=i; j++) {
 8                 System.out.print("*");
 9             }
10             System.out.println();
11         }
12     }
13 }

 

转载于:https://www.cnblogs.com/PerZhu/p/10864955.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值