易错考点: 1.通过类名不可以调用实例方法,可访问静态成员。 2.通过对象名可以访问静态成员,和非静态成员。 3.静态方法不能直接调用非静态方法,而实例方法可访问静态方法。
4.自定义类时不允许定义如下方法public void toString() { }。 因为toString方法是内置在Object中的方法,重写的方法必须和父类一模一样。
重载:1.在同一个类中。2.方法名必须相同。3.与修饰符和返回值无关,不能修改。4.可修改参数列表,通过改变参数的类型、顺序、个数)进行重载。
重写:1.必须和父类方法一模一样。2.子类的方法权限必须大于等于父类的方法权限。
基础知识点:import java.awt.print.Printable;
import java.util.Arrays;
import java.util.Scanner;
class Main{
public static void main(String[] args) {
double a=3.1415926;
System.out.printf("%.4f",a); //C语言输出
Scanner sc=new Scanner(System.in);
int b=sc.nextInt();
sc.nextLine(); //吸收换行符及本行之后字符
String s=sc.nextLine();
System.out.println(b+" "+s);
int[] c=new int[] {1,2,3,4,5};
System.out.println(Arrays.toString(c)); //数组转化为String类型输出
int[] d=Arrays.copyOf(c, 3);
System.out.println(Arrays.toString(d));
}
}
自定义异常类:
class Main{
public static void main(String[] args) throws Myexception { //抛出自己写的异常
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
if(a>0)
System.out.println("输入年龄合法。");
else {
throw new Myexception("非法年龄");
}
}
}
class Myexception extends Exception
{
public Myexception() {
// TODO Auto-generated constructor stub
}
Myexception(String s){
super(s);
}
}
常用系统类
public class Main {
public static void main(String[] args) {
int a=Integer.parseInt("123",8); //其他进制转化为十进制,返回类型为整数类型
System.out.println(a);
String b=Integer.toString(83,8); //十进制转化为其他进制,返回类型为String
int b1=Integer.parseInt(b); //字符串转为其他类型
System.out.println(b1);
String s="abcdefgh";
s=s.replace("a", "b"); //替换
int k=s.indexOf("bdd"); //查询子串
System.out.println(k);
System.out.println(s);
StringBuffer s1=new StringBuffer(s); //转为Stringbuffer,可变字符串
s1.append("ttt");
System.out.println(s1);
System.out.println(s1.reverse()); //翻转
s1.replace(0, 3, "aaa"); //指定范围(左闭右开)替换
System.out.println(s1);
s1.toString();
System.out.println(s1+"-------------");
BigInteger x=new BigInteger("123456789"); //大数计算
BigInteger y=new BigInteger("123456789");
BigInteger z=x.multiply(y);
System.out.println(z);
double g=3.1415926;
System.out.printf("%5.2f\n",g); //日期格式化
Date now=new Date();
SimpleDateFormat sdf=new SimpleDateFormat("yyyy:MM:dd hh:mm:ss");
System.out.println(sdf.format(now));
Calendar calendar=Calendar.getInstance();
System.out.println(calendar.getTime());
System.out.println(sdf.format(calendar.getTime()));
}
}
栈的应用 括号匹配
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
Stack st=new Stack();
String s=sc.next();
int flag=0;
for(int i=0;i
关注
打赏
最近更新
- 深拷贝和浅拷贝的区别(重点)
- 【Vue】走进Vue框架世界
- 【云服务器】项目部署—搭建网站—vue电商后台管理系统
- 【React介绍】 一文带你深入React
- 【React】React组件实例的三大属性之state,props,refs(你学废了吗)
- 【脚手架VueCLI】从零开始,创建一个VUE项目
- 【React】深入理解React组件生命周期----图文详解(含代码)
- 【React】DOM的Diffing算法是什么?以及DOM中key的作用----经典面试题
- 【React】1_使用React脚手架创建项目步骤--------详解(含项目结构说明)
- 【React】2_如何使用react脚手架写一个简单的页面?