java语言程序设计与数据结构(基础篇)第二章答案
答案为本人自己求解,若有错误,还望海涵并及时告知。如有雷同,纯属巧合。
2.1
import java.util.Scanner; public class Welcome
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter a degree in Celsius:");
double celsius = input.nextDouble();
System.out.println(celsius+"Celsius is "+((9.0/5)*celsius+32)+" Fahrenheit");
}
}
2.2
import java.util.Scanner; public class Welcome
{
public static void main(String[] args)
{
final double PI = 3.1415926;
Scanner input = new Scanner(System.in);
System.out.print("Enter the radius and length of a cylinder:");
double radius = input.nextDouble();
double length = input.nextDouble();
double area = radius * radius * PI;
System.out.println("The area is "+area);
System.out.println("The volume is "+(area * length));
}
}
2.3
import java.util.Scanner; public class Welcome
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter a value for feet:");
double feet = input.nextDouble();
System.out.println(feet+" feet is "+(feet * 0.305)+" meters");
}
}
2.4
import java.util.Scanner; public class Welcome
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter a number in pounds:");
double pounds = input.nextDouble();
System.out.println(pounds+" pounds is "+(pounds * 0.454)+" kilograms");
}
}
2.5
1 import java.util.Scanner;
2
3 public class Welcome
4 {
5 public static void main(String[] args)
6 {
7 Scanner input = new Scanner(System.in);
8 System.out.print("Enter the subtotal and a gratuity rate:");
9 int fee = input.nextInt();
10 int rate = input.nextInt();
11 System.out.println("The gratuity is $"+fee * rate / 100.0+" and total is $"+(fee + fee * rate / 100.0));
12 }
13 }
2.6
import java.util.Scanner; public class Welcome
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter a number between 0 and 1000:");
int num = input.nextInt();
int oneP = num % 10;
int tenP = (num - oneP) % 100 / 10;
int hunP = (num - oneP - tenP) / 100;
System.out.println("The sum of the digits is "+(oneP+tenP+hunP));
}
}
2.7
import java.util.Scanner; public class Welcome
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter the number of minutes:");
long min = input.nextLong();
long remainingday = min / (24 * 60);
long day = remainingday % 365;
long year = remainingday / 365;
System.out.println(min+" minutes is approximately "+year+" years and "+day+" days");
}
}
2.8
2.9
import java.util.Scanner; public class Welcome
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter v0,v1,and t:");
float v0 = input.nextFloat(),v1 = input.nextFloat(),t = input.nextFloat();
float a = (v1 - v0) / t;
System.out.println("The average acceleration is "+a);
}
}
2.10
import java.util.Scanner; public class Welcome
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter the amount of water in kilograms:");
double amount = input.nextDouble();
System.out.print("Enter the initial temperature:");
double initialT = input.nextDouble();
System.out.print("Enter the final temperature:");
double finalT = input.nextDouble();
System.out.println("The energy needed is "+(amount * (finalT - initialT) * 4184));
}
}
2.11
2.12
import java.util.Scanner; public class Welcome
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter speed and acceleration:");
double speed = input.nextDouble(),acceleration = input.nextDouble();
System.out.println("The mininum runway length for this airplane is "+(speed * speed / (2 * acceleration)));
}
}
2.13
2.14
import java.util.Scanner; public class Welcome
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter weight in pounds:");
double weight = input.nextDouble();
System.out.print("Enter height in inches:");
double height = input.nextDouble();
double kg = weight * 0.45359237,m = height * 0.0254;
System.out.println("BMI is "+(kg / (m * m)));
}
}
2.15
import java.util.Scanner; public class Welcome
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter x1 and y1: ");
double x1 = input.nextDouble(),y1 = input.nextDouble();
System.out.print("Enter x2 and y2: ");
double x2 = input.nextDouble(),y2 = input.nextDouble();
double distance = Math.pow(Math.pow(x2 - x1,2 ) + Math.pow(y2 - y1, 2),0.5);
System.out.println("The distance between the two points is "+distance);
}
}
2.16
import java.util.Scanner; public class Welcome
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter the length of the side: ");
double length = input.nextDouble();
double area = 3.0 / 2 * Math.pow(3, 0.5) * length *length;
System.out.println("The area of the hexagon is "+area);
}
}
2.17
2.18
2.19
2.20
2.21
2.22
2.23
java语言程序设计与数据结构(基础篇)第二章答案的更多相关文章
- Java语言程序与数据结构(基础篇)-随记
有关代码见BasicJava U1-Java概述 1-程序设计风格和文档 1.注释风格 注释:// ; 块注释:/* ~ / ; javadoc注释:/* ~ */ javadoc注释 eg. /** ...
- Java语言程序设计(基础篇)第二章
第二章 基本程序设计 2.2 编写简单的程序 1.变量名尽量选择描述性的名字(descriptive name). 2.实数(即带小数点的数字)在计算机中使用一种浮点的方法来表示.因此,实数也称为浮点 ...
- Java编程基础篇第二章
关键字 概述:被Java语言赋予特定含义的单词. 特点:组成关键字的字母全部为小写字母. 标识符 概述:给类,接口,包,方法,常量起名字时的字符序列 组成规则:英文大小写字母,数字,$和— 命名规则. ...
- Java语言程序设计与数据结构(基础篇)第七章答案
答案为本人求解,如有错误,还望海涵.如有雷同,纯属巧合. 7.1 import java.util.Scanner; public class Main { public static void ma ...
- java语言程序设计与数据结构(基础篇)第四章答案
4.1 import java.util.Scanner; public class Welcome { public static void main(String[] args) { Scanne ...
- 从零开始的程序逆向之路基础篇 第二章——用OllyDbg(OD)分析一个简单的软件
作者:Crazyman_Army 原文来自:https://bbs.ichunqiu.com/thread-43469-1-1.html 0x00知识回顾 (由于笔者省事,没开XP虚拟机,而且没关闭A ...
- 《java 语言程序设计》第3、4章编程练习
3.1 public class test { public static void main(String[] args) { System.out.println("Enter a, b ...
- 明解C语言 入门篇 第二章答案
练习2-1 #include <stdio.h> int main() { int x; int y; int percent; puts("请输入两个整数"); pr ...
- 明解C语言 中级篇 第二章答案
练习2-1 /* 倒计时后显示程序运行时间 */ #include <time.h> #include <stdio.h> /*--- 等待x毫秒 ---*/ int slee ...
随机推荐
- 【Google Cloud技术咨询】「Contact Center AI」引领我们走向高度智能客服的时代
前提背景 我们距离"不再智障"的智能客服还有多远?对于智能客服,用户一直都是"批评多于褒奖",究其原因是在于人们对于AI客服的期待很高,而AI客服在实际应用中的 ...
- Spring Data JPA实体的生命周期总结
目录 四种状态 API示例 persist remove merge refresh 参考链接 四种状态 首先以一张图,简单介绍写实体生命周期中四种状态之间的转换关系: 瞬时(New):瞬时对象,刚N ...
- 跨平台APP推荐收藏
时间:2019-04-11 整理:pangYuaner 标题:十大跨平台优秀软件 地址:https://www.cnblogs.com/the-king-of-cnblogs/p/3154758.ht ...
- ubuntu 2018 apt 代理proxy设置
永久设置 打开代理文件,好像默认没有,98proxy是自己新建的 sudo gedit /etc/apt/apt.conf.d/98proxy 在打开的文件中输入如下内容,其中username和pas ...
- 前端~定位属性position(relative、absolute、fixed)的分析
前端~定位属性position(relative.absolute.fixed)的分析 1,简单了解: relative:移动自身时,参考自身的原来位置而移动,移动子元素(子元素设置了absolute ...
- Android系统编程入门系列之应用内数据保存数据库
上篇文章已经介绍了如何使用SharedPreferences存储键值对形式的轻量级数据,对于那些相同结构的多组数据,类似于存储Java中定义的类的多个对象属性值,如果按照键值对的形式一条条读写,需要分 ...
- Intel® QAT加速卡之逻辑实例
Intel QAT加速卡逻辑实例 1. QAT相关的名词组织关系 在本手册中描述的平台上,处理器可以连接到一个或多个英特尔通信芯片组8925至8955系列(PCH)设备. 从软件角度来看,每个PCH设 ...
- github上使用C语言实现的线程池
网上介绍线程池的知识很多,但是在代码实现上介绍的又不是那么多.而且给人的一种感觉就是:你的这种实现是正规的方式还是你自己的实现? 如果有这么个疑问,且想找一个靠谱的代码拿来使用,那么这个项目是个不错的 ...
- Servlet体系结构
一.使用HttpServlet 其中,HttpServlet在重写的service()方法中对http请求的共7中提交方式进行了判断,所以只要我们只要重写对应的请求方式处理逻辑方法 doGet()和d ...
- 小白也能看懂的dubbo3应用级服务发现详解
搜索关注微信公众号"捉虫大师",后端技术分享,架构设计.性能优化.源码阅读.问题排查.踩坑实践. 本文已收录 https://github.com/lkxiaolou/lkxiao ...