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 ...
随机推荐
- 基于CentOS7.x Linux操作系统,从0开始构建一套Docker虚拟化平台,使用二进制Tar包方式,部署的步骤和方法如下:
#配置centos7的yum源#建议阿里源#链接:https://yq.aliyun.com/articles/525282?type=2#从Docker官网下载软件包: ls -l docker-1 ...
- Android Jetpack基本架构之ViewModel+LiveData+DataBinding入门
前提:导入所有依赖,开启DataBinding app的build.gradle android { defaultConfig { ... dataBinding { enabled true } ...
- XML基础——extensible markup language
一.xml概念 1.xml和html区别 其中,xml是纯文本文件,跨语言:浏览器有html解析器也有xml解析器: 2.和properties配置文件区别 二.xml语法 1.基本语法 三.xml组 ...
- LVS负载均衡集群--DR模式部署
目录: 一.LVS-DR数据包流向分析 二.DR 模式的特点 三.LVS-DR中的ARP问题 四.DR模式 LVS负载均衡群集部署 一.LVS-DR数据包流向分析 1.为方便进行原理分析,将clien ...
- CommonsBeanutils1 分析笔记
1.PropertyUtils.getProperty commons-beanutils-1.9.2.jar 包下的 PropertyUtils#getProperty方法相对于getXxx方法,取 ...
- 记录一次sql注入绕过
目标:http://www.xxxxx.net/temp.asp?ID=10359 通过 and 1=1 and 1=2 测试发现存在拦截 首先想到 and 空格 = 可能存在触发规则 一般遇到这种情 ...
- CTFd+ubuntu service搭建等待更新
CTFd是一款基于Apache2.0的协议的开源CTF平台,最新版本目前为1.20.该平台功能强大,基本上能够满足目前的CTF竞赛需求,同时,该平台提供了强大的插件功能,可以自己进行插件开发实现自己的 ...
- 边缘使用 K8s 门槛太高?OpenYurt 这个功能帮你快速搭建集群!
OpenYurt作为阿里巴巴首个开源的边缘云原生项目,涉及到边缘计算和云原生两个领域.然而,许多边缘计算的开发者并不熟悉云原生相关的知识.为了降低 OpenYurt 的使用门槛,帮助更多地开发者快速上 ...
- 10.6Java学习
1.类,对象,方法的定义.2.标识符分为两类:关键字/常见的基本类型:boolean(布尔型),byte(字节型),char(字符型),double(双精度),float(浮点),int(整型),lo ...
- 【Python学习】1.数据类型
一.整数 可以使用十进制和十六进制来表示整数.比如:-1000和0x1e3f2d 二.浮点数 直接表示浮点数,比如:2.443或者1.2e5 1.2e-10等 整数和浮点数在计算机内部存储的方式是不同 ...