java上机实验(Lab1.xls)

 

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!");
   }
}

84a3275675bdae0820568ffc5918f535.png

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);
       }
       }

   }
}

 

ac4b577a887cb64377ef6a676afdc845.png

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("无法构成三角形");
           }
       }
}

 

ebb541f40e5497f1894ff550085fe198.png

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Code Slacker

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值