2.1

public class test {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double f, c;
c = input.nextDouble();
f = (9.0/5)*c+32;
System.out.println(f);
}
}

2.2

public class test {
public static void main(String[] args) {
double r, h;
final double PI = 3.1415925;
System.out.println("Enter the radius and length of a cylinder: ");
Scanner input = new Scanner(System.in);
r = input.nextDouble();
h = input.nextDouble();
System.out.println("The area is " + PI*r*r);
System.out.println("The volume is " + PI*r*r*h);
}
}

2.3

public class test {
public static void main(String[] args) {
double f, m;
Scanner input = new Scanner(System.in);
System.out.println("Enter a value for feet: ");
f = input.nextDouble();
System.out.println(f + " feet is " + 0.305 *f + " meters");
}
}

2.4

public class test {
public static void main(String[] args) {
double p, k;
Scanner input = new Scanner(System.in);
System.out.println("Enter a number in pounds: ");
p = input.nextDouble();
System.out.println(p + " pounds is " + 0.454 * p + " kilograms");
}
}

2.6

public class test {
public static void main(String[] args) {
int n, sum, t;
Scanner input = new Scanner(System.in);
System.out.println("Enter a number between 0 and 1000: ");
n = input.nextInt();
sum = 0;
t = n % 10;
while(t != 0) {
sum += t;
n /= 10;
t = n % 10;
}
System.out.println("The sum of the digits is " + sum);
}
}

2.7

public class test {
public static void main(String[] args) {
int m = 0;
int years, days, t;
System.out.println("Enter the number of minutes: ");
Scanner input = new Scanner(System.in);
m = input.nextInt();
t = (m / 60) / 24;
years = t / 365;
days = t % 365;
System.out.println(m + " minutes is approximately " + years + " years and " + days + "days.");
}
}

2.8

public class test {
public static void main(String[] args) {
int n;
char c;
Scanner input = new Scanner(System.in);
System.out.print("Enter an ASCII code: ");
n = input.nextInt();
c = (char)n;
System.out.println("The character for ASCII code " + n + " is " + c); }
}

2.11

public class test {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter employee's name: ");
String name = input.next();
System.out.println("Enter number of hours worked in a week: ");
float hours = input.nextFloat();
System.out.println("Enter hourly pay rate: ");
float payRate = input.nextFloat();
System.out.println("Enter federal tax withholding rate: ");
float ftwr = input.nextFloat();
System.out.println("Enter state tax withholding rate: ");
float stwr = input.nextFloat();
System.out.println("Employee Name " + name);
System.out.println("Hours Worked " + hours);
System.out.println("Pay Rate: $" + payRate);
System.out.println("Gross Pay: $" + hours * payRate);
System.out.println("Deductions:");
System.out.println(" Federal Withholding (" + ftwr * 100 +"%): $" + payRate * ftwr);
System.out.println(" State Withholding (" + stwr * 100 +"%): $" + payRate * stwr);
System.out.println(" Total Deduction: $" + payRate * (ftwr + stwr);
}
}

2.12

public class test {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter balance and interest rate (e.g., 3 for 3%): ");
double balance = input.nextDouble();
double rate = input.nextDouble();
System.out.printf("The interest is %.4f", balance * (rate / 1200));
}
}

2.13

public class test {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
//System.out.println("Enter balance and interest rate (e.g., 3 for 3%): ");
System.out.print("Enter investment amount: ");
double investmount = input.nextDouble();
System.out.print("Enter monthly interest rate: ");
double rate = input.nextDouble();
System.out.print("Enter number of years: ");
int year = input.nextInt();
double s = investmount * Math.pow((1 + rate / 100), (year * 12));
System.out.println("Accumulated value is " + s);
}
}

2.14

public class test {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter weigth in pounds: ");
float weigth = input.nextFloat();
System.out.print("Enter heigth in inches: ");
float height = input.nextFloat();
System.out.println("BMI is " + 0.45359237 * weigth / Math.pow(height * 0.0254, 2));
}
}

2.15

public class test {
public static void main(String[] args) {
double t, s;
s = t = 0;
Scanner input = new Scanner(System.in);
for(int i = 0; i < 6; i++) {
s = (100 + t) * (1 + 0.00417);
t = s;
}
System.out.println("After six months, result is: " + s);
}
}

2.16

public class test {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the amount of water in kilogram: " );
double m = input.nextDouble();
System.out.print("Enter the initial temperature: " );
double it = input.nextDouble();
System.out.print("Enter the final temperature: " );
double ft = input.nextDouble();
System.out.println("The energy needed is " + m * (ft - it) * 4184);
}
}

2.17

public class test {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the temperature in Fahrenheit: " );
double f = input.nextDouble();
System.out.print("Enter the wind miles per hour: ");
double speed = input.nextDouble();
System.out.println("The wind chill index is " + (35.74 + 0.6215 * f - 35.75 * Math.pow(speed, 0.16) + 0.427 * f * Math.pow(speed, 0.16)));
}
}

2.18

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

《java 语言程序设计》第2章编程练习的更多相关文章

  1. 梁勇Java语言程序设计第三章全部例题 为第五次作业

    完成例题3-1,通过系统当前时间毫秒值获取随机10以内的整数判断加的结果是否正确,不用if语句 package com.swift; import java.util.Scanner; public ...

  2. Java面向对象程序设计第9章1-9

    Java面向对象程序设计第9章1-9 1. 线程和进程的联系和区别是什么? 联系: 一个进程可以包括多个线程. 区别: 进程: 进程是一个具有一定独立功能的程序关于某个数据集合的一次运行活动,它是系统 ...

  3. Java语言程序设计-助教篇

    1. 给第一次上课(软件工程)的老师与助教 现代软件工程讲义 0 课程概述 给学生:看里面的第0个作业要求 2. 助教心得 美国视界(1):第一流的本科课堂该是什么样?(看里面的助教部分) 助教工作看 ...

  4. Java面向对象程序设计第14章3-8和第15章6

    Java面向对象程序设计第14章3-8和第15章6 3.完成下面方法中的代码,要求建立一个缓冲区,将字节输入流中的内容转为字符串. import java.io.*; public class tes ...

  5. Java面向对象程序设计第8章3-5

    Java面向对象程序设计第8章3-5 3.String类型有什么特点? 一旦赋值,便不能更改其指向的字符对象 如果更改,则会指向一个新的字符对象 不能为null 4.String什么时候进行值比较,什 ...

  6. Java面向对象程序设计第7章1-8

    Java面向对象程序设计第7章1-8 1."程序中凡是可能出现异常的地方必须进行捕获或拋出",这句话对吗? 不对. 异常分两类,runtime异常和非runtime异常. runt ...

  7. Java语言程序设计(基础篇)第一章

    第一章 计算机.程序和Java概述 1.1 引言 什么是程序设计呢? 程序设计就是创建(或者开发)软件,软件也称为程序. 1.2 什么是计算机 计算机是存储和处理数据的电子设备,计算机包括硬件(har ...

  8. 0031 Java学习笔记-梁勇著《Java语言程序设计-基础篇 第十版》英语单词

    第01章 计算机.程序和Java概述 CPU(Central Processing Unit) * 中央处理器 Control Unit * 控制单元 arithmetic/logic unit /ə ...

  9. 《JAVA语言程序设计》上课笔记

    教学目标:1.使学生了解JAVA课程的性质.定位.作用:为什么要学习JAVA?让学生知道如何学好JAVA: 教学内容: 一.        问几个问题 1.             你们到这里来干什么 ...

  10. Java语言程序设计复习提纲

     这是我在准备Java考试时整理的提纲,如果是通过搜索引擎搜索到这篇博客的师弟师妹,建议还是先参照PPT和课本,这个大纲也不是很准确,自己总结会更有收获,多去理解含义,不要死记硬背,否则遇到概念辨析题 ...

随机推荐

  1. anaconda-anaconda无法安装pydot?

    只需先安装graphviz,再安装pydot就可以了 sudo conda install graphviz sudo conda install pydot

  2. 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 xor (根号分治)

    xor There is a tree with nn nodes. For each node, there is an integer value a_ia​i​​, (1 \le a_i \le ...

  3. 关于maven工程的几个BUG

    换了个新的环境,重新导入的maven工程出现了2个BUG: 1.Could not calculate build plan: Plugin org.apache.maven.plugins:mave ...

  4. 缩略图信息提取工具vinetto

    缩略图信息提取工具vinetto   在Windows操作系统中,为了方便用户快速浏览图片,系统会自动为每个图片生成预览图.预览图默认保存在同目录的Thumbs.db文件中.当图片文件删除后,Thum ...

  5. Kail Linux渗透测试教程之ARP侦查Netdiscover端口扫描Zenmap与黑暗搜索引擎Shodan

    Kail Linux渗透测试教程之ARP侦查Netdiscover端口扫描Zenmap与黑暗搜索引擎Shodan ARP侦查工具——Netdiscover Netdiscover是一个主动/被动的AR ...

  6. 使用matplotlib绘图(四)之散点图

    # 使用matplotlib绘制散点图 import numpy as np import matplotlib.pyplot as plt # 设置全局刻度标签大小 plt.rcParams['xt ...

  7. FastReport.Net使用:[22]地图(Map)控件

    标记有学生地区 1.在报表中放一个地图控件 将地图控件放在标题区即可,其他栏目删除. 2.双击地图控件进行地图添加. 可以再网上下载到地图数据,ESRI shapefile文件,本例中找了个省会城市地 ...

  8. [转]Intent和IntentFilter详解

        Intent   Android中提供了Intent机制来协助应用间的交互与通讯,Intent负责对应用中一次操作的动作.动作涉及数据.附加数据进行描述,Android则根据此Intent的描 ...

  9. hdu 4119 Isabella's Message 模拟题

    Isabella's Message Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.p ...

  10. PAT甲级1089. Insert or Merge

    PAT甲级1089. Insert or Merge 题意: 根据维基百科: 插入排序迭代,消耗一个输入元素每次重复,并增加排序的输出列表.每次迭代,插入排序从输入数据中删除一个元素,在排序列表中找到 ...