×

java面试题及答案 java java面试题

java面试题:一个人早上八点上山,晚上八点到达山顶第二天早上八点下山,晚上八点到达山底?Java Applet怎么运行

admin admin 发表于2022-07-02 23:00:44 浏览121 评论0

抢沙发发表评论

java面试题:一个人早上八点上山,晚上八点到达山顶第二天早上八点下山,晚上八点到达山底


java面试题的解析方式(思路如下):

public static void main(String args) {

// TODO Auto-generated method stub

int up = 8;

int down = 8;

while(up《=20){

if((up == 20-6) &&(up == 20-6)){

System.out.println(“在“+up+“时到达同一地点“);

break;

}

up += 1;

down += 1;

}

}

微软面试题的背后

微软的奇葩面试题答案并不重要,重要的是思考过程,而思考过程体现了你是否拥有公司所看重的能力,不仅是微软,其他公司的面试也是为了测试你的某种能力,如果你提前培养了这种能力,相当于知道了面试的“考纲”,在面试中自然就从容不迫,游刃有余了。-java面试题及答案

平时要知道转化能力是看透问题,然后找到解决方案的能力。所以转化能力最重要的是如何看透问题,也就是你思考问题的方式。


Java Applet怎么运行


1.首先编写java文件,如下:
import java.awt.*;
import java.applet.*;
public class Java_Graphics extends Applet {
public void paint(Graphics g) {
g.drawString(“用Graphics写字和画图的基本方法“, 20,40);
g.drawOval(100, 100, 30, 30);
g.drawOval(200, 100, 40, 25);
g.drawLine(20, 140, 200,140);
g.drawRect(20, 160, 50, 80);
g.drawRoundRect(110, 160, 100, 100, 25, 18);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
javac Java_Graphics.java 编译完成后生成 java_Graphics.class
这将是在浏览器中执行的程序(.class文件)
2.其次,编写对应的Html文件:
《!doctype html》
《html》
《head》
《meta charset=“UTF-8“》
《meta name=“Generator“ content=“EditPlus®“》
《meta name=“Author“ content=““》
《meta name=“Keywords“ content=““》
《meta name=“Description“ content=““》
《title》My First Java Applet《/title》
《/head》
《body》
Here’s my First Java Applet:
《applet code= “Java_Graphics.class“ width = “300“ height = “300“》
《/body》
《/html》
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
》 想来大家都知道,最重要的当然这句《applet code= “Java_Graphics.class“ width = “300“
》 height = “300“》,加载了.class文件
1
2
3.浏览器解释执行:
点击html文件,你可以看到你想看到的效果,(paint()所画)~~
-java

java反射调用方法可以传非基本类型吗如对象、接口


可以的,参数类型是没有限制的。通过以下代码可以证明。

接口:

public interface MyInterface {
    void print();
}

实现类:

public class MyInterfaceImpl implements MyInterface {
    @Override
    public void print() {
        System.out.println(“interfaceImpl“);
    }
}

通过反射调用方法:

import java.lang.reflect.Method;

public class Test {

    public static void main(String args) throws Exception {
        Test instance = Test.class.newInstance();
        Method method = Test.class.getDeclaredMethod(“test“, MyInterface.class);
        MyInterface myInterface = new MyInterfaceImpl();
        method.invoke(instance, myInterface);
    }

    public void test(MyInterface myInterface) {
        myInterface.print();
    }
}