package _4;
import java.util.LinkedList;
import java.util.Scanner;
public class A {
public boolean Judge(int o) {
if(o!=2&&o!=4&&o!=8&&o!=16) {
System.out.println("error");
return false;
}
else
return true;
}
public void Binary(int i) {
LinkedList<Object> a = new LinkedList<Object>();
while(i!=0) {
a.add(i%2);
i=(i-i%2)/2;
}
System.out.println("转化为二进制=")
for(int j=0;j<a.size();j++) {
System.out.print(a.getLast());
a.removeLast();
}
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int r = 0;int obj = 0;
System.out.println("请输入数: 请输如进制: ");
r = in.nextInt();
obj = in.nextInt();
while(Judge(r)) {
}
}
}
书写代码的过程中遇到while内部以自定义函数为判断条件时报错的情况:
java中 静态方法不可以直接调用非静态方法和成员,也不能使用this关键字。静态的方法调用了非静态的方法所以报错。类中静态的方法或者属性,本质上来讲并不是该类的成员,在java虚拟机装载类的时候,这些静态的东西已经有了对象,它只是在这个类中暂时存在,不需要通过类的构造器(构造函数)类实现实例化;而非静态的属性或者方法,在类的装载是并没有存在,需在执行了该类的构造函数后才可依赖该类的实例对象存在。所以在静态方法中调用非静态方法时,编译器会报错(Cannot make a static reference to the non-static method func() from the type A)。
- java中不能将方法体内的局部变量声明为static
- main()函数是静态的,没有返回值,形参为数组。
- 非静态成员的可以随便调用静态成员