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. mp4文件数据格式解析

    unsigned int(32)[3]    32*3bit string[32]  32*8bit class VisualSampleEntry(codingname) extends Sampl ...

  2. keycloak学习

    keycloak 是一个针对Web应用和RESTfull Web API 提供SSO(Single Sign On:单点登陆),它是一个开源软件,源码地址是:https://github.com/ke ...

  3. shell-命令行参数(转)

    命令行参数 (转自http://c.biancheng.net/cpp/view/2739.html) 特殊变量列表 变量 含义 $0 当前脚本的文件名 $n 传递给脚本或函数的参数.n 是一个数字, ...

  4. 《java虚拟机》----java内存模型与线程

    No1. No2. java内存模型规定了所有的变量都存储在主内存中(Main Memory)中 每条线程还有自己的工作内存(Working Memory) 线程的工作内存中保存了被该线程使用到的变量 ...

  5. Python 2.7.x 和 3.x 版本的语法区别

    <__future__模块> Python 3.x引入了一些与Python 2不兼容的关键字和特性,在Python 2中,可以通过内置的__future__模块导入这些新内容.如果你希望在 ...

  6. java 抽象类 接口 区别

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha 接口 里面 都是抽象方法. 接口里面的 字段 都是 public static fina ...

  7. Tsinsen 最长双回文串

    求最长双回文串,正反建回文树求最大. 题目链接:http://www.tsinsen.com/ViewGProblem.page?gpid=A1280 By:大奕哥 #include<bits/ ...

  8. BZOJ1004 HNOI Cards

    第一次学习置换群这个东西. 这题需要利用Burnside定理. 即我们求出循环节为一(转完不变)的个数的平均数也就是等价类的个数. 定义:设G={a1,a2,…ag}是目标集[1,n]上的置换群.每个 ...

  9. [转载]for循环的执行顺序

    原文地址:for循环的执行顺序作者:想飞上天的美人鱼   for循环的执行顺序用如下表达式: for(expression1;expression2;expression3) { expression ...

  10. [转]String.Replace 和 String.ReplaceAll 的区别

    JAVA 中的 replace replaceAll 问题: 测试code System.out.println("1234567890abcdef -----> "+&qu ...