Java语言程序设计(基础篇)(原书第10版) 第一章编程练习题

Java语言程序设计(基础篇)(原书第10版) 第一章编程练习题

心血来潮补一下之前没做完的课后题,争取全部做完,欢迎大家评论指正。

在这里插入图片描述

需要书籍或者相关资料可以私聊!!!

1-1 显示三条消息

public class Program1_1 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		System.out.println("Welcome to Java!");
		System.out.println("Welcome to Computer Science!");
		System.out.println("Programming is fun!");
	}

}

1-2 显示五条消息

public class Program1_2 {

   public static void main(String[] args){
       for(int i = 1; i <= 5; i++)
           System.out.println("Welcome to Java");
   }

}

1-3 显示图案

public class Program1_3 {

    public static void main(String[] args) {
        System.out.println("    J     A     V     V     A");
        System.out.println("    J    A A     V   V     A A");
        System.out.println("J   J   AAAAA     V V     AAAAA");
        System.out.println(" J J   A     A     V     A     A");
    }

}

1-4 打印表格

public class Program1_4 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
        System.out.println("a     a^2     a^3");
        System.out.println("1     1       1");
        System.out.println("2     4       8");
        System.out.println("3     9       27");
        System.out.println("4     16      64");
	}

}

1-5 计算表达式

public class Program1_5 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		System.out.println("(9.5*4.5-2.5*3)/(45.5-3.5) = " 
				+ (9.5*4.5-2.5*3)/(45.5-3.5));
	}

}

1-6 数列求和

public class Program1_6 {

    public static void main(String[] args) {
        int sum = 0;
        for (int i = 1; i < 10; i++)
            sum += i;
        System.out.println(sum);
    }

}

1-7 近似求PI

public class Program1_7 {

    public static void main(String[] args) {
        double m = 0, t = 0, f = 1;
        for (int i = 1; i <= 13; i += 2) {
            t += 1.0 * f / i;
            if(i == 11) m = t;
            f *= -1;
        }
        System.out.println(m*4);
        System.out.println(t*4);
    }

}

1-8 圆的面积和周长

public class Program1_8 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		float pi = (float) 3.14159265;
		float c = (float) (2*5.5*pi);
		float s = (float) (5.5*5.5*pi);
		System.out.println("半径为5.5的圆的周长为" + c);
		System.out.println("半径为5.5的圆的面积为" + s);
	}

}

1-9 矩形的面积和周长

public class Program1_9 {

    public static void main(String[] args) {
        double a = 4.5, b = 7.9;

        System.out.printf("宽为%.1f, 高为%.1f的矩形的周长为%.2f\n", a, b, (a+b)*2);
        System.out.printf("宽为%.1f, 高为%.1f的矩形的面积为%.2f\n", a, b, a*b);
    }

}

1-10 以英里计的平均速度

public class Program1_10 {

    public static void main(String[] args) {
        double s = 14 / 1.6;
        int second = 45 * 60 + 30;
        double h = second / 3600.0;
        System.out.println(s / h);
    }

}

1-11 人口估算

public class Program1_11 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		double add = 365*24*60*60/7.0 - 365*24*60*60/13.0 + 365*24*60*60/45.0;
		System.out.printf("first : %.0f\n", (312032486 + add));
		System.out.printf("second : %.0f\n", (312032486 + add*2));
		System.out.printf("third : %.0f\n", (312032486 + add*3));
		System.out.printf("forth : %.0f\n", (312032486 + add*4));
		System.out.printf("fifth : %.0f\n", (312032486 + add*5));
	}

}

1-12 以公里计的平均速度

public class Program1_12 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		float v;
		v = (float) ((24*1.6)/(1+40/60.0+35/3600.0));
		System.out.println("速度为 :" + v);
	}

}

1-13 代数:求解2*2线性方程

public class Program1_13 {

    public static void main(String[] args) {
        double a = 3.4, b = 50.2, c = 2.1, d = 0.55, e = 44.5, f = 5.9;
        double x1 = e*d - b*f, y1 = a*f - e*c, m = a*d - b*c;
        System.out.println("x = " + x1/m);
        System.out.println("y = " + y1/m);
    }

}
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值