《Java语言程序设计与数据结构》编程练习答案(第二章)(二)

英文名:Introduction to Java Programming and Data Structures, Comprehensive Version, 11th Edition

2.13

import java.util.Scanner;
public class book {public static void main(String[] args){Scanner input = new Scanner(System.in);System.out.print("Enter the monthly saving amount:");double m = input.nextDouble();double sum = 0.0;for(int i=0;i<6;i++)sum = (m+sum)*(1+0.00417);System.out.println("After the sixth month, the account value is $"+sum+".");}
}

2.14

import java.util.Scanner;
public class book {public static void main(String[] args){Scanner input = new Scanner(System.in);System.out.print("Enter weight in pounds:");double pounds = input.nextDouble();System.out.print("Enter height in inches:");double inches = input.nextDouble();double bmi = pounds*0.4535927/(inches*inches*0.0254*0.0254);System.out.println("BMI is "+bmi+".");}
}

2.15

import java.util.Scanner;
public class book {public static void main(String[] args){Scanner input = new Scanner(System.in);System.out.print("Enter x1 and y1:");double x1 = input.nextDouble();double y1 = input.nextDouble();System.out.print("Enter x2 and y2:");double x2 = input.nextDouble();double y2 = input.nextDouble();double d = Math.pow((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1),0.5);System.out.println("The distance between the two points is "+d+".");}
}

2.16

import java.util.Scanner;
public class book {public static void main(String[] args){Scanner input = new Scanner(System.in);System.out.print("Enter the length of the side:");double s = input.nextDouble();double a = 3*Math.pow(3,0.5)/2*s*s;System.out.println("The area of the hexagon is "+a+".");}
}

2.17

import java.util.Scanner;
public class book {public static void main(String[] args){Scanner input = new Scanner(System.in);System.out.print("Enter the temperature in Fahrenheit:");double ta = input.nextDouble();System.out.print("Enter the wind speed (>=2) in miles per hour:");double v = input.nextDouble();double twc = 35.74+0.6215*ta-35.75*Math.pow(v,0.16)+0.4275*ta*Math.pow(v,0.16);System.out.println("The wind chill is "+twc);}
}

2.18

public class book {public static void main(String[] args){System.out.println("a    b    pow(a,b)");for(int i = 1;i <= 5;i++)System.out.println(i+"    "+(i+1)+"    "+(int)Math.pow(i,i+1));}
}

2.19

import java.util.Scanner;
public class book {public static void main(String[] args){Scanner input = new Scanner(System.in);System.out.println("Enter the coordinates of three points separated by spaces");System.out.print("like x1 y1 x2 y2 x3 y3:");double x1 = input.nextDouble();double y1 = input.nextDouble();double x2 = input.nextDouble();double y2 = input.nextDouble();double x3 = input.nextDouble();double y3 = input.nextDouble();double s1 = Math.pow((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2),0.5);double s2 = Math.pow((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3),0.5);double s3 = Math.pow((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3),0.5);double s = (s1+s2+s3)/2;double a = Math.pow(s*(s-s1)*(s-s2)*(s-s3),0.5);System.out.println("The area of the triangle is "+a);}
}

2.20

import java.util.Scanner;
public class book {public static void main(String[] args){Scanner input = new Scanner(System.in);System.out.print("Enter balance and interest rate:");double balance = input.nextDouble();double rate = input.nextDouble();double interest = balance*(rate/1200);System.out.println("The interest is "+interest);}
}

2.21

import java.util.Scanner;
public class book {public static void main(String[] args){Scanner input = new Scanner(System.in);System.out.print("Enter investment amount:");double amount = input.nextDouble();System.out.print("Enter annual interest rate in percentage:");double ar = input.nextDouble();System.out.print("Enter number of years:");int y = input.nextInt();double fv = amount*Math.pow(1+ar/1200,y*12);System.out.println("Future value is $"+fv);}
}

2.22

import java.util.Scanner;
public class book {public static void main(String[] args){Scanner input = new Scanner(System.in);System.out.print("Enter an amount in int, for example 114514:");int amount = input.nextInt();int old = amount;int numberOfOneDollars = amount/100;amount%=100;int numberOfQuarters = amount/25;amount%=25;int numberOfDimes = amount/10;amount%=10;int numberOfNickles = amount/5;amount%=5;int numberOfPennies = amount;System.out.println("Your amount "+old+" consists of");System.out.println("    "+numberOfOneDollars+" dollars");System.out.println("    "+numberOfQuarters+" quarters");System.out.println("    "+numberOfDimes+" dimes");System.out.println("    "+numberOfNickles+" nickels");System.out.println("    "+numberOfPennies+" pennies");}
}

2.23

import java.util.Scanner;
public class book {public static void main(String[] args){Scanner input = new Scanner(System.in);System.out.print("Enter the driving distance:");double distance = input.nextDouble();System.out.print("Enter miles per gallon:");double youhao = input.nextDouble();System.out.print("Enter price per gallon:");double youjia = input.nextDouble();double price = distance/youhao*youjia;System.out.println("The cost of driving is $"+price);}
}

第二章 完

《Java语言程序设计与数据结构》编程练习答案(第二章)(二)相关推荐

  1. 《Java语言程序设计与数据结构》编程练习答案(第七章)(一)

    <Java语言程序设计与数据结构>编程练习答案(第七章)(一) 英文名:Introduction to Java Programming and Data Structures, Comp ...

  2. 《Java语言程序设计与数据结构》编程练习答案(第三章)(三)

    <Java语言程序设计与数据结构>编程练习答案(第三章)(三) 英文名:Introduction to Java Programming and Data Structures, Comp ...

  3. 《Java语言程序设计与数据结构》编程练习答案(第四章)(二)

    <Java语言程序设计与数据结构>编程练习答案(第四章)(二) 英文名:Introduction to Java Programming and Data Structures, Comp ...

  4. 《Java语言程序设计与数据结构》编程练习答案(第四章)(一)

    <Java语言程序设计与数据结构>编程练习答案(第四章)(一) 英文名:Introduction to Java Programming and Data Structures, Comp ...

  5. java考试安徽工业大学_2011~2012《Java语言程序设计》试卷A及答案(安徽工业大学)...

    <2011~2012<Java语言程序设计>试卷A及答案(安徽工业大学)>由会员分享,可在线阅读,更多相关<2011~2012<Java语言程序设计>试卷A及 ...

  6. 南开大学java考试试题_2014秋学期南开大学《Java语言程序设计》在线作业附答案...

    2014秋学期南开大学<Java语言程序设计>在线作业附答案 1.下列代码中,将引起一个编译错误的行是(D). 1)public class Test{ 2) int m,n; 3) pu ...

  7. 自考04747《java语言程序设计(一)》课件_自考04747《java语言程序设计(一)》课后习题答案全集...

    <自考04747<java语言程序设计(一)>课后习题答案全集>由会员分享,可在线阅读,更多相关<自考04747<java语言程序设计(一)>课后习题答案全集 ...

  8. java语言程序设计期末考试试题及答案_《JAVA语言程序设计》期末考试试题及答案1-7.doc...

    <JAVA语言程序设计>期末考试试题及答案1-7 社望斡工耪纱访肝讫否稗仗族锯滥祥缀疏霹辐螟丁哥联退控罐绳屑铸氛券误滚烫周瞎鲸明垢礁蛀撞瓶蔬辗撞往件沽囊炕蔫消辉孽层束沁吨减攻匿少纳涡唆晚亦 ...

  9. (1 24) 3 java代码_《Java语言程序设计》测试题及参考答案(第1部分)

    一.单项选择题 1.Java Applet编程时用户的Applet程序类的正确定义是哪一种 ? (1)class MyApplet extends applet{ } (2)class MyApple ...

最新文章

  1. 深度学习:梯度下降算法改进
  2. 编写有效的事条指导原则
  3. object-c 入门基础篇
  4. 中间件是什么?在.NET Core中的工作原理又是怎样的呢?
  5. Layer弹出层关闭后刷新父页面
  6. 如何才能精通C++?原来这点才最重要!
  7. Silverlight 中的 CoreCLR
  8. 【SpringBoot_ANNOTATIONS】AOP 01 AOP功能测试
  9. ubuntu18下成功安装Remastersys备份当前系统成ISO文件
  10. c# oracle 中文列名,sql中中文列名
  11. 完全理解android事件分发机制
  12. Arduino ESP8266利用SPIFFS上传文件和查看文件
  13. 这6款APP和游戏,是苹果选出的2019年年度最佳
  14. Python实现箱形图的绘制
  15. matlab reff,R语言逻辑回归和泊松回归模型对发生交通事故概率建模
  16. Restful-API设计最佳实战--Django播客系统(五)
  17. VS2015问题:stack around the variable “XX” was corrupte
  18. ROK(万国觉醒)服务器卡顿解决方案
  19. 【python】choice函数
  20. 1.1程序设计(C语言基础)

热门文章

  1. 啰里吧嗦式讲解java静态代理动态代理模式
  2. [嵌入式]S5PV210微处理器GPIO编程
  3. tplink怎么进去_tp login.cn登陆入口进不去怎么办
  4. 氮化物 ITO-Ag复合薄膜/Si—P(111)和Si—P(100)两种不同Si片做基底制备TiNx薄膜/立方氮化硼聚晶(PcBN)复合物
  5. 电影《野马分鬃》观后感-20211129
  6. 安装opencv踩坑笔记
  7. 启明医疗完成收购Cardiovalve公司股权;全球首个且唯一红细胞成熟剂利布洛泽中国获批治疗β-地中海贫血 | 医药健闻...
  8. html中使用vue组件
  9. 没有Unity_光追2008年的书 Ray Tracing From The Ground Up 目录翻译
  10. ZEDmini在Jetson AGX Xavier中使用ROS运行