导航菜单
首页 >  » 正文

C语言编程题 题目:任意输入4个点,求围成四边形的面积是多少? 一道JAVA编程题:用类描述汽车中Engine(发动机)的功率和Gearbox(变速箱)的档位数目

C语言编程题 题目:任意输入4个点,求围成四边形的面积是多少?

我测试过了,四点一线,凹四边形,四边形,有两个点共点,都可以,这里使用一条知道N边形N个顶点坐标求N边形的面积的公式,这些情况其实已经可以不考虑,呵呵,自动求
凹四边形情况:

有三点共一线形成三角形的情况:



#include "stdio.h"
#include "math.h"
void main()
{
 double x[4],y[4];
 for(int i=0;i<4;i++)
 {
  scanf("%lf%lf",&x[i],&y[i]);
 }
 double mianji=0.0;
 for(int ii = 1 ; ii< 4 ; ii++)
 {
  mianji+=(x[ii-1]*y[ii]-x[ii]*y[ii-1]);
 }
 mianji+=x[3]*y[0]-x[0]*y[3];
 mianji= fabs(0.5*mianji);
 printf("%lf ",mianji);
}

一道JAVA编程题:用类描述汽车中Engine(发动机)的功率和Gearbox(变速箱)的档位数目

--------Engine 类----------
public class Engine {
int power;
public int getPower() {
return power;
}
public void setPower(int power) {
this.power = power;
}
}
----------Gearbox类---------
public class Gearbox {
int amount;
public int getAmount() {
return amount;
}
public void setAmount(int amount) {
this.amount = amount;
}
}
-------------Car 类---------------
public class Car {
Engine engine = new Engine();
Gearbox gearbox = new Gearbox();
public Engine getEngine() {
return engine;
}
public void setEngine(Engine c) {
this.engine = c;
}
public Gearbox getGearbox() {
return gearbox;
}
public void setGearbox(Gearbox h) {
this.gearbox = h;
}
public void show(){
int power = engine.getPower();
int amount = gearbox.getAmount();
System.out.println("功率为:"+power+" 变速箱:"+amount);
}
}
---------------test 类--------------------
public class test {
public static void main(String[] args) {
Engine engine = new Engine();
engine.setPower(123);
Gearbox gearbox = new Gearbox();
gearbox.setAmount(6);
Car jeep = new Car();
jeep.setEngine(engine);
jeep.setGearbox(gearbox);
jeep.show();
}
}
这种题太没32313133353236313431303231363533e59b9ee7ad9431333335346139营养了...看你应该是个初学者,又在线等,帮你一把.

全国计算机等级考试二级JAVA最后的操作题用什么编程软件?

按标准是没有编程软件的……是给你txt文本文件,让你补全横线上的代码,改错题还有编程题也是用文本文件的,所以该背的还是多背下吧,平时Eclipse用Alt+/习惯了到时候就坑了。
全国计算机等级考试(National Computer Rank Examination,简称NCRE)是经原国家教育委员会(现教育部)批准,由教育部考试中心主办,面向社会,用于考察应试人员计算机应用知识与技能的全国性计算机水平考试体系。包括二级考试的内容如程序修改、程序设计与调试。
考生不受年龄、职业、学历等背景的限制,任何人均可根据自己学习情况和实际能力选考相应的级别和科目。考生可携带有效身份证件到就近考点报名。每次考试报名的具体时间由各省(自治区、直辖市)级承办机构规定。

JAVA编程题求全部代码

class HW1 {
    public static void main(String[] args) {
        double[] test = new double[]{5.2, 1.0, 6.7, 3.4, 100.5, 55.5};
        BoundryValues boundryValues = getBoundryValues(test);
        System.out.println("Min Value = " + boundryValues.getMin());
        System.out.println("Max Value = " + boundryValues.getMax());
        System.out.println("Ave Value = " + boundryValues.getAve());
    }
    private static class BoundryValues {
        private double max;
        private double min;
        private double ave;
        public BoundryValues(){}
        public BoundryValues(double max, double min, double ave) {
            this.max = max;
            this.min = min;
            this.ave = ave;
        }
        public void setMax(double max) {
            this.max = max;
        }
        public double getMax() {
            return max;
        }
        public void setMin(double min) {
            this.min = min;
        }
        public double getMin() {
            return min;
        }
        public void setAve(double ave) {
            this.ave = ave;
        }
        public double getAve() {
            return ave;
        }
    }
    public static BoundryValues getBoundryValues(double[] doubles) {
        BoundryValues boundryValues = new BoundryValues();
        double[] results = sort(doubles);
        double total = 0.0;
        for (int i = 0; i < results.length; i ++) {
            total += results[i];
        }
        boundryValues.setMin(results[0]);
        boundryValues.setMax(results[results.length - 1]);
        boundryValues.setAve(total/results.length);
        return boundryValues;
    }
    public static double[] sort(double[] doubles) {
        for (int i = 0; i < doubles.length; i ++) {
            for (int j = 0; j < doubles.length - i - 1; j ++) {
                if (doubles[j] > doubles[j + 1]) {
                    double temp = doubles[j];
                    doubles[j] = doubles[j + 1];
                    doubles[j + 1] = temp;
                }
            }
        }
        return doubles;
    }
}import java.util.*;
class HW2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        double a, b, c;
        System.out.println("Enter a, b, c:");
        a = scanner.nextDouble();
        b = scanner.nextDouble();
        c = scanner.nextDouble();
        Setsets = calculate(a, b, c); for (Double d : sets) { System.out.println("Values are: " + d + " "); } } public static Set calculate(double a, double b, double c) { Set sets = new HashSet(); if (Math.pow(b, 2.0) - 4 * a * c < 0) { System.err.println("No value"); } else { sets.add((- b + Math.sqrt(Math.pow(b, 2.0) - 4 * a * c)) / 2.0 * a); sets.add((- b - Math.sqrt(Math.pow(b, 2.0) - 4 * a * c)) / 2.0 * a); } return sets; } }下午接着写

java编程题:求所有两位数内能被3整除的和及不能被三整除的数的和~拜托了

var i,j:integer;
j:=0;
for i=10 to 99 do
begin
if i mod 3 = 0 then j=j+1;
end;
showmessage(能被3整除的两位数有+inttostr(j)+个,不能被3整除的两位数有+inttostr(100-j)+个);

java编程题:随机产生20个50~100之间的整数,输出这20个数并找出最大数和最小数。

public class P1 {
private int[] num=new int[20];
private int Maxnum,Minnum;
public P1(){
for(int i =0;i&lt;20;i++){
num[i]=50+(int)(Math.random()*50);
}
}
public void print(){
for(int j=0;j&lt;20;j++){
System.out.print(num[j]+" ");
}
System.out.println();
}
public void setMaxAndMin(){
Maxnum=Minnum=num[0];
for(int k=1;k&lt;20;k++){
if(Maxnum&lt;num[k]){
Maxnum=num[k];
}else if(Minnum&gt;num[k]){
Minnum=num[k];
}
}
}
public int getMax(){
return Maxnum;
}
public int getMin(){
return Minnum;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
P1 p = new P1();
p.print();
p.setMaxAndMin();
System.out.println("最大值为:"+p.getMax());
System.out.println("最小值为:"+p.getMin());
}
}

一个JAVA编程题 用以计算y年m1月d1日与同年的m2月d2之间的天数(m2>=m1),并打印计算结果。.若m1=m2且d1=d2则算1天.在闰年时,2月有29天.闰年的年号由以下方式确定:该年号能被4整除但不能被100整除,或者该年号能被400整除则是闰年.例:输入1997,

Calendar类,你最好的选择,假如不允许使用这些类库的话,只让很基础的做的话,只需要很多个if语句罢了 public class Calc { private int year; private int startMonth; private int startDay; private int endMonth; private int endDay; public Calc(int year,int startMonth,int startDay,int endMonth,int endDay){ this.year = year; this.startMonth = startMonth; this.startDay = startDay; this.endMonth = endMonth; this.endDay = endDay; } public int calcDay() throws Exception{ if(!validate()){ throw new Exception("麻烦别输入错误的日期"); } int day = 0; for(int i = startMonth+1;i<endMonth;i++){ day+= getMonthDay(i); } day+=endDay; day+=(getMonthDay(startMonth)-startDay+1); return day; } /** * 校验数据是否准确,自己写 * @return */ public boolean validate(){ return true; } public int getMonthDay(int month) throws Exception{ if(month==2){ if((year%4==0&&year%100!=0)||year%400==0){ return 29; }else{ return 28; } }else if(month==1){ return 31; }else if(month==3){ return 31; }else if(month==4){ return 30; }else if(month==5){ return 31; }else if(month==6){ return 30; }else if(month==7){ return 31; }else if(month==8){ return 31; }else if(month==9){ return 30; }else if(month==10){ return 31; }else if(month==11){ return 30; }else if(month==12){ return 31; }else{ throw new Exception("You input wrong month!"); } } public static void main(String[] args) throws Exception { Calc c = new Calc(1997, 2, 27, 3, 10); System.err.println(c.calcDay()); } }

相关推荐: