-
字符串长度方法 length()
-
Math.floor(3.4) //3.0 向下取整
-
Math.ceil(3.4) //4.0 向上取整
-
2>8&&9<2 //false 两边都是false
-
实现接口的关键字是 implements
-
String str = “hello”
str.subtring(1,2) //输出e 从0数 1-2(不取到2)
-
三大特性 //封装 继承 多态
-
-5%3 // -2
-
try…catch //try包裹可能出错的内容 catch包裹报错后执行的内容
-
int a=2 a+=3 //a=5
-
随机数函数 //random
- if语句中的条件表达式的值可以是int型数据(×)
- 在switch语句中的条件表达式必须要有default选项(×)
- 声明变量时必须指定一个类型(✓)
- 构造方法是类的一种特殊函数,它的方法名必须与类名相同(✓)
- java语言中允许一个类实现多个接口(✓)
- abstract类的子类必须是非抽象类(×)
- final类可以有子类(×)
- 不允许同时final和abstract修饰同一个方法(✓)
- string类是final类不可以有子类(✓)
- 允许接口中只有一个抽象方法(✓)
- 源文件中public类可以有0个或多个(✓)
- java语言中允许一个类继承多个类(错)
- 构造方法一般在创新对象时,系统会自动调用(✓)
- 可以同时用final和abstract修饰同一个方法(×)
- java中局部变量没有默认值(✓)
- 接口中的常量可以不指定初值(×)
- 不存在继承关系的情况下也可以实现重写(×)
- 可以在接口中只声明变量不定义方法(✓)
- 类中static修饰变量式方法可以用类名或对像访问(✓)
- 字符串ABC===ABC的值是true(✓)
- x:-5
- y:-1
public static void main(String[] args) {
int x = 1,y = 6;
while (y-->0){
x--;
}
System.out.println("x:"+x+"y:"+y);
}
阅读程序-2
- 输出-100
class D{
int x=100,y=200;
public void setX(int x) {
x = x;
}
public void setY(int y) {
this.y = y;
}
public int getXYsum() {
return x+y;
}
}
public class cy {
public static void main(String[] args) {
D d = new D();
d.setX(-100);
d.setY(-200);
System.out.println(d.getXYsum());
}
}
阅读程序-3
- 输出 11 和 110
class A{
public int getNumber(int a) {
return a+1;
}
}
class B extends A{
public int getNumber(int a) {
return a+100;
}
}
public class cy {
public static void main(String[] args) {
A a = new A();
System.out.println(a.getNumber(10)); //
a = new B();
System.out.println(a.getNumber(10));//
}
}
程序题
十以内的阶乘之和
public static void main(String[] args) {
int sum=0;
int a = 1;
for (int i = 1;i<=10;i++){
a=a*i;
sum = sum+a;
}
System.out.println(sum);
}
求累加一万以内最大整数
public static void main(String[] args) {
int sum = 0;
int flg=0;
for (int i = 1; i < 10000; i++) {
sum += i;
if (sum < 10000) {
flg=i;
} else {
System.out.println("最大正整数:" + flg);//140
break;
}
}
}
方法的考察–1
- 类名retong,宽高double类型默认是1
- 无参构造方法
- 给定宽高的构造方法
- getmj 返回面积的方法
- getzc 返回周长的方法
class retong{
double witdh = 1;
double height = 1;
retong(){
System.out.println("无参构造方法");
}
retong(double w,double h){
this.witdh = w;
this.height = h;
System.out.println("有参构造方法");
}
double getmj(){
return witdh*height;
}
double getzc(){
return witdh*2+height*2;
}
}
public class cy {
public static void main(String[] args) {
retong a = new retong(2,4); //给定宽高
System.out.println(a.getmj());
System.out.println(a.getzc());
}
}
方法的考察–2
- 类名radius,宽高double类型
- 无参构造方法
- 定义一个 static PI (静态)
- 给定半径的构造方法
- getmj 返回面积的方法
- getzc 返回周长的方法
class radius{
double radius;
static double PI = 3.14;
radius(){
System.out.println("无参构造方法");
}
radius(double r){
this.radius = r;
System.out.println("指定半径的有参构造方法");
}
double getmj(){
return PI*radius*radius;
}
double getzc(){
return PI*(2*radius);
}
}
public class cy {
public static void main(String[] args) {
radius a = new radius(13); //给定半径
System.out.println(a.getmj());
System.out.println(a.getzc());
}
}
需要注意的知识点



