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. LeetCode 628. 三个数的最大乘积

    题目描述 LeetCode 628. 三个数的最大乘积 给定一个整型数组,在数组中找出由三个数组成的最大乘积,并输出这个乘积. 示例1 输入: [1,2,3] 输出: 6 示例2 输入: [1,2,3 ...

  2. 解决CentOS7关闭/开启防火墙出现Unit iptables.service failed to load: No such file or directory.

    CentOS7中执行 service iptables start/stop 会报错Failed to start iptables.service: Unit iptables.service fa ...

  3. Linux与其它类Unix内核的比较

    单块结构的内核:由几个逻辑上独立的成分构成,单块结构,大多数据商用Unix变体也是单块结构: 编译并静态连接的传统Unix内核:Linux能自动按需动态地装载和卸载部分内核代码(模块),而传统Unix ...

  4. 关于button标签会刷新页面的问题

    当button标签在form表单里面时,这时点击button按钮会提交表单刷新页面. <form action=""> <button>点击</but ...

  5. HDU 5876 Sparse Graph(补图上BFS)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5876 题意: 有一个 n 个点无向图,再给你 m 对顶点, 代表着这 m 对顶点之间没有边, 除此之外 ...

  6. 利用gmpy2破解rsa

    gmpy2的相关文档: https://gmpy2.readthedocs.io/en/latest/ ================ 题目: 来自实验吧的rsarsa:http://www.shi ...

  7. am335xSD卡启动--文件系统制作

    1.网上下载busybox工具https://busybox.net/downloads/ 2.根据此文章提示制作自己的跟文件系统 链接: https://pan.baidu.com/s/1bp6GK ...

  8. POJ2185 Milking Grid KMP两次(二维KMP)较难

    http://poj.org/problem?id=2185   大概算是我学KMP简单题以来最废脑子的KMP题目了 , 当然细节并不是那么多 , 还是码起来很舒服的 , 题目中描写的平铺是那种瓷砖一 ...

  9. 利用dll加载漏洞实现远程代码执行

    微软的“不安全dll加载”漏洞涉及Windows XP至Windows 7等多个版本的操作系统.由于Windows存在加载未指明完整路径的dll文件的机制,可能导致用户在使用第三方软件.玩游戏.听音乐 ...

  10. ZOJ 3707 Calculate Prime S 数论

    思路:容易得到s[n]=s[n-1]+s[n-2],也就是fib数. 求第k小的fib质数的也就是第k个质数数-2,当k>2时. 在就是s[n]/x%m=s[n]%(x*m)/x. 代码如下: ...