2021-09-13

练习1

  1. 定义一个Test02类
  2. 在类中定义主方法
  3. 在主方法中,使用输出语句,输出如下变量

        (1)整数变量i1: 88, i2:-88

        (2)小数变量d: 88.888

        (3)字符变量ch1: 'A', ch2:'8'

        (4)布尔变量flag1: true, flag2:false

package com.itlwh;

public class Test02 {
	public static void main(String[] args) {
		int i1=88;
		int i2=-88;
		float d =88.888F;
		char ch1 = 'A',ch2='B';
		boolean flag1 = true,flag2=false;
		System.out.println(i1);
		System.out.println(i2);
		System.out.println(d);
		System.out.println(ch1);
		System.out.println(ch2);
		System.out.println(flag1);
		System.out.println(flag2);
	}
}

练习2

  1. 定义一个Test03类
  2. 在类中定义主方法
  3. 在主方法中,使用输出语句,输出一段话
  4. 输出效果如下:

好好学习~天天向上~键盘敲烂,月薪过万~~

package com.itlwh;

public class Test03 {
	public static void main(String[] args) {
		System.out.println("好好学习~");
		System.out.println("天天向上~");
		System.out.println("键盘敲烂,月薪过万~~");
	}
}

练习3

  1. 定义一个类,类名Test04
  2. 在类中定main方法
  3.    *

      * *

     *   *

    *     *

     *   *

      * *

       *


    在main方法中,使用输出语句输出如下图形:
package com.itlwh;

public class Test04 {
	public static void main(String[] args) {
		System.out.println("   *  ");
		System.out.println("  ** ");
		System.out.println(" *  * ");
		System.out.println("*    *");
		System.out.println(" *  * ");
		System.out.println("  ** ");
		System.out.println("   *  ");
	}
}

练习4

  1. 定义一个类,类名Test05
  2. 在类中定main方法
  3. 在main方法中,使用输出语句输出如下图形.

                  {@}

                   /|\

                    |

package com.itlwh;

public class Test05 {
	public static void main(String[] args) {
		System.out.println("{@}");
		System.out.println("/|\\");
		System.out.println(" |");
	}
}

练习5

  1. 定义一个类,类名Test06
  2. 在类中定main方法
  3. 在main方法中,使用输出语句输出如下图形:

*

**

***

****

package com.itlwh;

public class Test06 {
	public static void main(String[] args) {
		System.out.println("*");
		System.out.println("**");
		System.out.println("***");
		System.out.println("****");
	}
}

练习6

找出以下代码的错误,并修改

         public class Task07_01 {

                  public static void main(String[] args) {

                          int a;

                          System.out.println(a); //错误:变量没有赋值不能使用

                          {

                                   int c = 20;

                                   System.out.println(c);

                          }

                          c = 30; //错误2:代码块内部定义的变量是局部变量 只能内部使用

                          System.out.println(c);

}

         }

        

         public class Task07_02 {

                  public static void main(String[] args) {

                          int x = 2;

                          {

                                   int y = 6;

                                   System.out.println("x is " + x);

                                   System.out.println("y is " + y);

                          }

                          y = x; //错误:y是局部变量

                          System.out.println("x is " + x);

                  }

         }

练习7

byte b1=3,b2=4,b;

                  b=b1+b2;

                  b=3+4;

 哪句是编译失败的呢?为什么呢?

答:b=b1+b2 类型不匹配b1+b2 会是int型

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值