鱼C论坛

 找回密码
 立即注册
查看: 2406|回复: 0

[学习笔记] JAVA学习Day1【变量&数据类型】

[复制链接]
发表于 2020-8-1 17:47:38 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
学习视频:https://www.bilibili.com/video/BV17J411G72L?p=20
【1-19】

  1. /*
  2. 练习1:打印个人信息
  3. */

  4. //System.out.println()分行显示 System.out.print()一行显示
  5. class TestExer1{
  6.         public static void main(String[] args) {
  7.                 System.out.println("小明");
  8.                 System.out.println(18);
  9.                 System.out.println('女');
  10.                 System.out.println(true);
  11.                 System.out.println(40.2);
  12.                 System.out.println("-------------------");
  13.                 System.out.print("fdfd");
  14.                 System.out.print('!');
  15.         }
  16. }

  17. //变量
  18. class TestVariable{
  19.         public static void main(String[] args) {
  20.                 int age = 10;
  21.                 System.out.print(age);
  22.         }
  23. }


  24. class DefineAndUseVariable{
  25.         public static void main(String[] args) {
  26.                 int age;
  27.                 age = 18;
  28.                 int age2 = 18;
  29.                 System.out.println(age);
  30.         }
  31. }
  32. //int double String char boolean


  33. class TestExer2{
  34.         public static void main(String[] args) {
  35.                 String name = "dfd";
  36.                 int age = 34;
  37.                 char gender = '女';
  38.                 double height = 152.2;
  39.                 boolean marray = false;
  40.                 System.out.println(name);
  41.                 System.out.println("性别:" + gender);
  42.                 System.out.println(height);
  43.                 System.out.println(marray);
  44.         }
  45. }



  46. /*
  47.     基本数据类型
  48. 1.整型 byte(-128 127) short(-32768 32767) int  long
  49. 2.小数 float double
  50. 3.字符 char
  51. 4.字符串 String
  52. 5.布尔 boolean
  53. long需要加L 或 l float需要加f 或 F
  54. */

  55. class TestType{
  56.         public static void main(String[] args) {
  57.                 boolean marry = false;
  58.                 if(marry) {
  59.                         System.out.println("已婚");
  60.                 }else {
  61.                         System.out.println("未婚");
  62.                 }
  63.                 long time = 3223444444222L;
  64.                 System.out.println(time);
  65.                 float f = 34.35f;
  66.                 System.out.println(f);
  67.         }
  68. }
  69. //字符常量可以用来表示转义字符'\n'(换行)'、'\t'(tab) '\b'(删除键)'\\' '"'  '\r'(回车键)
  70. //还可以表示'\u字符的unicode编值的十六位进制形式'


  71. class TestExer3{
  72.         public static void main(String[] args) {
  73.                 String bookName = "fdfd";
  74.                 String author = "dfdf";
  75.                 double price = 100.1;
  76.                 int sale = 1;
  77.                 int amout = 100;
  78.                 boolean cu = false;
  79.                 System.out.println("书名:" + bookName);
  80.         }
  81. }
复制代码

本帖被以下淘专辑推荐:

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-28 19:11

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表