Programming Assignment 1: Hello, World

Here is the original link

  • HelloWorld.java
public class HelloWorld{
	public static void main(String[] args)
	{
		System.out.println("Hello, World");
	}
}
  • HelloGoodbye.java
public class HelloGoodbye{
	public static void main(String[] args)
	{
		System.out.println("Hello " + args[0] + " and " + args[1] + ".");
		System.out.println("Goodbye " + args[1] + " and " + args[0] + ".");
	}
}
  • RightTriangle.java(判断三角形是否为直角三角形)
public class RightTriangle{
	public static void main(String[] args)
	{
		int a = Integer.parseInt(args[0]);
		int b = Integer.parseInt(args[1]);
		int c = Integer.parseInt(args[2]);
		boolean arePositive = a > 0 && b > 0 && c > 0;
		boolean isRightTriangle = a*a + b*b == c*c || a*a + c*c == b*b || b*b + c*c == a*a;
		System.out.println(arePositive && isRightTriangle);
	}
}
  • GreatCircle.java(用近似公式求解地球上两点的距离)
public class GreatCircle{

	public static void main(String[] args)
	{
		double r = 6371.0;
		double x1 = Double.parseDouble(args[0]);
		x1 = Math.toRadians(x1);
		double y1 = Double.parseDouble(args[1]);
		y1 = Math.toRadians(y1);
		double x2 = Double.parseDouble(args[2]);
		x2 = Math.toRadians(x2);
		double y2 = Double.parseDouble(args[3]);
		y2 = Math.toRadians(y2);
		double distance = 2 * r * Math.asin(Math.sqrt(Math.pow(Math.sin((x2 - x1) / 2), 2) + Math.cos(x1) * Math.cos(x2) * Math.pow(Math.sin((y2 - y1) / 2), 2)));
		System.out.println(distance + " kilometers");
	}
}
  • CMYKtoRGB.java(将CMYK的数据转化为RGB值)
public class CMYKtoRGB{
	public static void main(String[] args)
	{
		double cyan = Double.parseDouble(args[0]);
		double magenta = Double.parseDouble(args[1]);
		double yellow = Double.parseDouble(args[2]);
		double black = Double.parseDouble(args[3]);

		double white = 1 - black;
		int red   = (int) Math.round(255 * white * (1 - cyan));
		int green = (int) Math.round(255 * white * (1 - magenta));
		int blue  = (int) Math.round(255 * white * (1 - yellow));

		System.out.println("red   = " + red);
		System.out.println("green = " + green);
		System.out.println("blue  = " + blue);
	}
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值