答案为本人自己求解,若有错误,还望海涵并及时告知。如有雷同,纯属巧合。

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语言程序设计与数据结构(基础篇)第二章答案的更多相关文章

  1. Java语言程序与数据结构(基础篇)-随记

    有关代码见BasicJava U1-Java概述 1-程序设计风格和文档 1.注释风格 注释:// ; 块注释:/* ~ / ; javadoc注释:/* ~ */ javadoc注释 eg. /** ...

  2. Java语言程序设计(基础篇)第二章

    第二章 基本程序设计 2.2 编写简单的程序 1.变量名尽量选择描述性的名字(descriptive name). 2.实数(即带小数点的数字)在计算机中使用一种浮点的方法来表示.因此,实数也称为浮点 ...

  3. Java编程基础篇第二章

    关键字 概述:被Java语言赋予特定含义的单词. 特点:组成关键字的字母全部为小写字母. 标识符 概述:给类,接口,包,方法,常量起名字时的字符序列 组成规则:英文大小写字母,数字,$和— 命名规则. ...

  4. Java语言程序设计与数据结构(基础篇)第七章答案

    答案为本人求解,如有错误,还望海涵.如有雷同,纯属巧合. 7.1 import java.util.Scanner; public class Main { public static void ma ...

  5. java语言程序设计与数据结构(基础篇)第四章答案

    4.1 import java.util.Scanner; public class Welcome { public static void main(String[] args) { Scanne ...

  6. 从零开始的程序逆向之路基础篇 第二章——用OllyDbg(OD)分析一个简单的软件

    作者:Crazyman_Army 原文来自:https://bbs.ichunqiu.com/thread-43469-1-1.html 0x00知识回顾 (由于笔者省事,没开XP虚拟机,而且没关闭A ...

  7. 《java 语言程序设计》第3、4章编程练习

    3.1 public class test { public static void main(String[] args) { System.out.println("Enter a, b ...

  8. 明解C语言 入门篇 第二章答案

    练习2-1 #include <stdio.h> int main() { int x; int y; int percent; puts("请输入两个整数"); pr ...

  9. 明解C语言 中级篇 第二章答案

    练习2-1 /* 倒计时后显示程序运行时间 */ #include <time.h> #include <stdio.h> /*--- 等待x毫秒 ---*/ int slee ...

随机推荐

  1. js调试之firbug

    说下几种方法吧: 1.用alert 这个最最直观 把你想要的内容弹出来给你看,但是要看哪里 就要在哪里加,比较麻烦 2.用firefox 或者chrome浏览器 里面有debug工具的 3.如果想用i ...

  2. 基于Linux系统ipython和集成开发环境Pycharm的安装

    1.简介 Python是一门跨平台的开源.免费的.解释型.面向对象.带有动态语义的脚本语言,同时也支持伪编译以进行优化和提高运行速度,还支持使用py2exe工具将Python程序转换为exe可执行程序 ...

  3. Linux下SSH以及SSH秘钥

    一.基于秘钥方式实现远程连接 第一步:创建密钥对(在管理端服务器上操作) 中间的输入项可以直接回车 ssh-keygen -t dsa 第二步:分发公钥(在管理端服务器执行) 这个步骤需要输入一个ye ...

  4. Sa-Token之注解鉴权:优雅的将鉴权与业务代码分离!

    Sa-Token之注解鉴权:优雅的将鉴权与业务代码分离! Sa-Token 介绍: Sa-Token 是一个轻量级 Java 权限认证框架,主要解决:登录认证.权限认证.Session会话.单点登录. ...

  5. elasticsearch入门到放弃之elasticsearch-head

    elasticsearch-head可理解为跟DBeaver一样是一个数据可视化工具,但是这个工具并没有理想中那么好用坑也是很多,我已经在我的github上fork了一份修改后的版本:https:// ...

  6. xshell与小键盘问题

    有些程序员的键盘是带有小数字键的,在使用xshell中文版时就可能出现一些小状况,本集就同大家分析一下使用数字键盘出现乱码的情况怎么办. 图1:使用数字小键盘出现乱码 问题描述: 在xshell上用v ...

  7. C#动态构建表达式树(三)——表达式的组合

    C#动态构建表达式树(三)--表达式的组合 前言 在筛选数据的过程中,可能会有这样的情况:有一些查询条件是公共的,但是根据具体的传入参数可能需要再额外增加一个条件.对于这种问题一般有两种方法: a. ...

  8. 内部类访问外部类成员变量,使用外部类名.this.成员变量

    public class Outer { private int age = 12; class Inner { private int age = 13; public void print() { ...

  9. 358 day09字节流、字符流

    day09[字节流.字符流] 主要内容 IO流 字节流 字符流 异常处理 Properties 教学目标 [ ] 能够说出IO流的分类和功能 [ ] 能够使用字节输出流写出数据到文件 [ ] 能够使用 ...

  10. 使用git克隆仓库到本地报错:SSL certificate problem: unable to get local issuer certificate

    第一次使用Git工具克隆仓库,使用的是HTTPS链接,失败了.发现是因为通过HTTPS访问时,如果服务器上的SSL证书未经过第三方机构认证,Git就会报错. 解决方法:通过命令关闭验证 git con ...