Java的基本语法们

标识符和关键字

  • 标识符:用来标识类名、变量名、方法名、类型名、数组名、文件名的有效字符序列。
  • 关键字:对Java编译器有特殊含义的字符串。

数据类型

  • 基本数据类型(其数据占用内存的大小固定,在内存中存入的是数值本身)
  1. 整数型(byte、short、int、long)
  2. 浮点数型(float、double)
  3. 字符型(char)
  4. 逻辑型 (boolean)
  • 引用数据类型(其在内存中存入的是引用数据的存放地址,而不是数据本身)
  1. 数组
  2. 类(class)
  3. 对象
  4. 接口(interface)

数据类型之间的相互转换

  • 自动类型转换
  • 强制类型转换

数组

public class Test {
	public static void main(String[] args) {
		int a[]=new int[5];//创建了一个长度为5的int型一维数组
		int[] b=new int[5];
		int c[]={1,2,3,4,5};
		
		System.out.println(a.length);//  5
		
		int A[][]=new int[5][1];
		int[][] B=new int[5][1];
		int C[][]= {{1},{2},{3},{4},{5}};
		
		System.out.println(A.length);// 5
	}
}

String类(java中专门操作字符串的类)

String的使用

运算符

if语句

循环语句

  • while循环语句
//计算1~99的整数和
public class Test {
	public static void main(String[] args) {
		int t=1;
		int sum=0;
		while(t<100) {
			sum+=t;
			t++;
		}
		System.out.println(sum);
	}
}
  • do…while循环语言
//计算1~99的整数和
public class Test {
	public static void main(String[] args) {
		int t=1;
		int sum=0;
		do{
			sum+=t;
			t++;
		}while(t<100); 
		System.out.println(sum);
	}
}
  • for循环语句
//计算1~99的整数和
public class Test {
	public static void main(String[] args) {
		int sum=0;
		for(int t=1;t<100;t++) {
			sum+=t;
		}
		System.out.println(sum);
	}
}

跳转语句

  • break语句
  • continue语句

输入输出

import java.util.Scanner;

public class Test {
	public static void main(String[] args) {
		
		Scanner input = new Scanner(System.in);//创建对象
		int a,b;
		String c;
		a=input.nextInt();//输入A
		b=input.nextInt();//输入B
		c=input.next();//输入字符串
		System.out.println("The a value is "+a);
		System.out.println("The b value is "+b);
		System.out.println("The c value is "+c);
		System.out.println("The a+b value is "+(a+b));
		
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值