Java语言程序设计与数据结构(基础篇)课后练习题 第四章(一)

}

4.3

================================================================

public class disizhang {

public static void main(String[] args){

double x1 = 35.2270869;

double y1 = -80.8431267;

double x2 = 32.0835407;

double y2 = -81.0998342;

double dcs = 6371.0*Math.acos(Math.sin(Math.toRadians(x1))*Math.sin(Math.toRadians(x2))+Math.cos(Math.toRadians(x1))*Math.cos(Math.toRadians(x2))*Math.cos(Math.toRadians(y1-y2)));

x2 = 33.7489954;

y2 = -84.3879824;

double dca = 6371.0*Math.acos(Math.sin(Math.toRadians(x1))*Math.sin(Math.toRadians(x2))+Math.cos(Math.toRadians(x1))*Math.cos(Math.toRadians(x2))*Math.cos(Math.toRadians(y1-y2)));

x1 = 28.5383355;

y1 = -81.3792365;

double doa = 6371.0*Math.acos(Math.sin(Math.toRadians(x1))*Math.sin(Math.toRadians(x2))+Math.cos(Math.toRadians(x1))*Math.cos(Math.toRadians(x2))*Math.cos(Math.toRadians(y1-y2)));

x2 = 32.0835407;

y2 = -81.0998342;

double dos = 6371.0*Math.acos(Math.sin(Math.toRadians(x1))*Math.sin(Math.toRadians(x2))+Math.cos(Math.toRadians(x1))*Math.cos(Math.toRadians(x2))*Math.cos(Math.toRadians(y1-y2)));

x1 = 33.7489954;

y1 = -84.0998342;

double das = 6371.0*Math.acos(Math.sin(Math.toRadians(x1))*Math.sin(Math.toRadians(x2))+Math.cos(Math.toRadians(x1))*Math.cos(Math.toRadians(x2))*Math.cos(Math.toRadians(y1-y2)));

double s1 = (dca+dcs+das)/2;

double s2 = (doa+dos+das)/2;

double a = Math.sqrt(s1*(s1-dca)(s1-dcs)(s1-das))+Math.sqrt(s2*(s2-doa)(s2-dos)(s2-das));

System.out.println(“The area is “+a+” km^2”);

}

}

4.4

================================================================

import java.util.Scanner;

public class disizhang {

public static void main(String[] args){

final double PI = 3.141592654;

Scanner input = new Scanner(System.in);

System.out.print("Enter the side: ");

double s = input.nextDouble();

double a = 6ss/(4*Math.tan(PI/6));

System.out.println("The area of the hexagon is "+a);

}

}

4.5

================================================================

import java.util.Scanner;

public class disizhang {

public static void main(String[] args){

final double PI = 3.141592654;

Scanner input = new Scanner(System.in);

System.out.print("Enter the number of sides: ");

int n = input.nextInt();

System.out.print("Enter the side: ");

double s = input.nextDouble();

double a = nss/(4*Math.tan(PI/n));

System.out.println("The area of the polygon is "+a);

}

}

4.6

================================================================

public class disizhang {

public static void main(String[] args){

final double PI = 3.141592654;

double alpha1 = Math.random()2PI;

double alpha2 = Math.random()2PI;

double alpha3 = Math.random()2PI;

double x1 = 40*Math.cos(alpha1);

double y1 = 40*Math.sin(alpha1);

double x2 = 40*Math.cos(alpha2);

double y2 = 40*Math.sin(alpha2);

double x3 = 40*Math.cos(alpha3);

double y3 = 40*Math.sin(alpha3);

double a = Math.sqrt((x1-x2)(x1-x2)+(y1-y2)(y1-y2));

double b = Math.sqrt((x2-x3)(x2-x3)+(y2-y3)(y2-y3));

double c = Math.sqrt((x1-x3)(x1-x3)+(y1-y3)(y1-y3));

double aa = Math.toDegrees(Math.acos((aa-bb-cc)/(-2b*c)));

double ab = Math.toDegrees(Math.acos((bb-aa-cc)/(-2a*c)));

double ac = Math.toDegrees(Math.acos((cc-bb-aa)/(-2a*b)));

System.out.println("The three angles are: “+aa+” “+ab+” "+ac);

}

}

4.7

================================================================

import java.util.Scanner;

public class disizhang {

public static void main(String[] args){

final double PI = 3.141592654;

Scanner input = new Scanner(System.in);

System.out.print("Enter the radius of the bounding circle: ");

double r = input.nextDouble();

double base = 0.1*PI;

System.out.println(“The coordinates of fibe points on the pentagon are”);

for(int i=0;i<5;i++)

{

System.out.printf(“(%.2f, %.2f)%n”,rMath.cos(base),rMath.sin(base));

base+=0.4*PI;

}

}

}

4.8

================================================================

import java.util.Scanner;

public class disizhang {

public static void main(String[] args){

Scanner input = new Scanner(System.in);

System.out.print("Ent6er an ASCII code: ");

int num = input.nextInt();

char str = (char)num;

System.out.printf(“The character for ASCII code %d is %c”,num,str);

}

}

4.9

================================================================

import java.util.Scanner;

public class disizhang {

public static void main(String[] args){

Scanner input = new Scanner(System.in);

System.out.print("Enter a character: ");

String jb = input.nextLine();

char str = jb.charAt(0);

int str2 = (int)str;

System.out.printf(“The Unicode for the character %c is %d”,str,str2);

}

}

4.10

=================================================================

public class disizhang {

public static void main(String[] args)

{

//在原来代码中进行修改

int answer = input.nextInt()修改为:char answer = input.nextLine().charAt(0)

if(answer1)—>if(answer’Y’)

}

}

4.11

=================================================================

import java.util.Scanner;

public class disizhang {

public static void main(String[] args){

System.out.print("Enter a decimal value (0 to 15): ");

Scanner input = new Scanner(System.in);

int num = input.nextInt();

if(num>=0&&num<=15){

if(num<10)

System.out.printf(“The hex value is %d”,num);

else

System.out.printf(“The hex value is %c”,‘A’+num-10);

}else

System.out.printf(“%d is an invalid input”,num);

}

  • 5
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值