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. javascript 进制转换(2进制、8进制、10进制、16进制之间的转换)

    //十进制转其他 var x=110; alert(x); alert(x.toString(8)); alert(x.toString(32)); alert(x.toString(16)); // ...

  2. PHP实现插入排序

    插入排序思想: 插入排序(Insertion Sort)的算法描述是一种简单直观的排序算法. 它的工作原理是通过构建有序序列,对于未排序数据,在已排序序列中从后向前扫描, 找到相应位置并插入.插入排序 ...

  3. 洛谷P1221 最多因子数 [搜索,数学]

    题目传送门 最多因子数 目描述 数学家们喜欢各种类型的有奇怪特性的数.例如,他们认为945是一个有趣的数,因为它是第一个所有约数之和大于本身的奇数. 为了帮助他们寻找有趣的数,你将写一个程序扫描一定范 ...

  4. asp.net core集成MongoDB

    0.目录 整体架构目录:ASP.NET Core分布式项目实战-目录 一.前言及MongoDB的介绍 最近在整合自己的框架,顺便把MongoDBD的最简单CRUD重构一下作为组件化集成到asp.net ...

  5. 工具栏(UIToolbar)

    工具栏一般用来显示弹出框,以至于UIPopoverController类包含方法presentPopoverFromBarButtonItem:permittedArrowDirections:ani ...

  6. 二. 创建Series和DataFrame对象

    创建对象 创建Series对象 Series可以通过列表,标量值,字典,ndarray,其他函数来创建 a = pf.Series([1,2,3,4]) # 列表创建 b = pd.Series(25 ...

  7. android studio 继续汉化 编译项目 菜单

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha Edit Flavors...

  8. [BZOJ4539][HNOI2016]树(主席树)

    4539: [Hnoi2016]树 Time Limit: 40 Sec  Memory Limit: 256 MBSubmit: 746  Solved: 292[Submit][Status][D ...

  9. 快速排序-C

    #include <stdio.h> #include <stdlib.h> #define N 6 int partition(int arr[], int low, int ...

  10. l1和l2正则化的区别 - 面试错题集

    L0:计算非零个数,用于产生稀疏性,但是在实际研究中很少用,因为L0范数很难优化求解,是一个NP-hard问题,因此更多情况下我们是使用L1范数L1:计算绝对值之和,用以产生稀疏性,因为它是L0范式的 ...