1. (简答题, 25分)Download and install the JDK from the Oracal website, configure the environment variables, debug and run the following example:
[Example] A simple Java Application program
--------------------------------
Program list:
public class HelloWorldDemo { // an application
public static void main(String args[]) {
System.out.println("Hello World!");
}
}
Please submit program code and the screenshot of the program output in the answer.
public class HelloWorldDemo {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
2. (简答题, 25分)Please write a Java program to output your name, age, height and weight, and run them through the JDK and Eclipse environment, respectively.
Please submit program code and the screenshot of the program output in the answer.(自己改一下数据即可)
public class information {
public static void main(String[] args) {
String name = "hhh";
int age = 99;
int height = 999;
int weight = 99;
System.out.println("name:" + name + " age:" + age + " height:" + height + " weight" + weight);
}
}
3. (简答题, 25分)Print out all the “Narcissistic number” between 100 and 1000. The so-called "Narcissistic number" refers to a three-digit number whose cubic sum of each number is equal to the number itself. For example: 153 is a "Narcissistic number" because 153=13+53+33.
Please submit program code and the screenshot of the program output in the answer.
public class Main {
public static void main(String[] args) {
int i;
int a,b,c;
for(i=100;i<1000;i++){//1000肯定不是
a=i%10;
b=i/10%10;
c=i/100;
if(i==(a*a*a+b*b*b+c*c*c))
{
System.out.println(i);
}
}
}
}
4. (简答题, 25分)Use the Point class in the Java class library to design a triangle class (Triangle), and output the area of the triangle.
Please submit program code and the screenshot of the program output in the answer.
import java.awt.Point;
import java.util.Scanner;
public class Triangle{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
double x1,x2,x3,y1,y2,y3;
System.out.println("请输入第一个点的x,y");
x1=sc.nextDouble();
y1=sc.nextDouble();
System.out.println("请输入第二个点的x,y");
x2=sc.nextDouble();
y2=sc.nextDouble();
System.out.println("请输入第三个点的x,y");
x3=sc.nextDouble();
y3=sc.nextDouble();
Point p1=new Point();
Point p2=new Point();
Point p3=new Point();
p1.setLocation(x1, y1);
p2.setLocation(x2, y2);
p3.setLocation(x3, y3);
double s1=p1.distance(p2);
double s2=p2.distance(p3);
double s3=p3.distance(p1);
if(s1+s2>s3 && s1+s3>s2 && s2+s3>s1)
{
double p=(s1+s2+s3)/2;
double area=Math.sqrt(p*(p-s1)*(p-s2)*(p-s3));
System.out.println("此三角形面积为:"+area);
}
else
{
System.out.println("无法构成三角形");
}
}
}