圆周面积
package CN.EDU.WWW;
import java.util.Scanner;
public class YuanZhuMianJi {
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
System.out.println("Enter a number for length of cylider e.g.5.5 12:");
double LengthOfCylider = input.nextDouble();
double area = LengthOfCylider *LengthOfCylider*3.14159;
System.out.println("area is " + area + "in area");
System.out.println("Enter a number for height e.g.12");
double Height = input.nextDouble();
double volume = area *Height/100.00;
System.out.println("volume is" + volume + "in volume");
}
}
华摄氏度
package CN.EDU.WWW;
import java.util.Scanner;
public class HuaShiDU {
public static void main(String[] args) {
/**输入一个函数;
* 打印百分度的华氏温度;
* celsius 摄氏温度读入一个double值;
* 根据公式:华氏温度=(9/5)*摄氏温度+32;
* 打印语句摄氏温度就是华氏温度的计算方式;
* 在这里要注意的是将(9/5)转换成(9.0/5)因为JAVA中使用除法,两个整数相除的结果为整数;必须加小数点。
*/
Scanner input = new Scanner(System.in);
System.out.println("Enter a drgree in celsius:");
double celsius = input.nextDouble();
double fahrenheit = (9.0 / 5) * celsius +32;
System.out.println("celsius" + celsius + "is" + fahrenheit + "in fahrenheit");
}
}
根号运算
package CN.EDU.WWW;
import java.util.Scanner;
public class GeHao {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double a = 5.50;
double b = 6.30;
double sqare = (Math.pow(2, 3)-Math.sqrt(4 * a * b));
double Sqareroot = (-b + sqare % 2 * a );
System.out.println("Sqareroot is" + (sqare % Sqareroot) );
}
}
银行贷款
package CN.EDU.WWW;
import java.util.Scanner;
public class GeHao {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double a = 5.50;
double b = 6.30;
double sqare = (Math.pow(2, 3)-Math.sqrt(4 * a * b));
double Sqareroot = (-b + sqare % 2 * a );
System.out.println("Sqareroot is" + (sqare % Sqareroot) );
}
}
正整数
package CN.EDU.WWW;
public class ZhengShu2116 {
public static void main(String[] args) {
double d = 3.45;
int i = (int)d;
System.out.println("i is" + i);
}
}
小数化整
package CN.EDU.WWW;
public class LeiXingZhuanHuan {
public static void main(String[] args) {
float f = 12.5F;
int i = (int)f;
System.out.println("f is" +f);
//小数部分被截去
System.out.println("f is" +i);
}
}
营业税金
package CN.EDU.WWW;
import java.util.Scanner;
public class Tax {
public static void main(String[] args) {
/**将营业税显示为保留小数点后两位;
* 创建一个函数值
* 输入一个数值
*用double值计算税金;
* 打印税金整数=税金*100%100;
* 表达值 (int) (tax * 100)/100.0将tax值向下四舍五入为保留小数点后两位。
* tax可以使用(int) (x * 100+0.5)/100;四舍五入为保留小数点后两位;
*
*/
Scanner input = new Scanner(System.in);
System.out.println("Enter purchase amount");
double purchaseAmount = input.nextDouble();
double tax = purchaseAmount *0.06;
System.out.println("Sales tax $" + (int) (tax * 100)/100.0);
}
}
P63页第2.3题将英尺换为米
package cn.edu.www;
import java.util.Scanner;
public class YingChiJiSuan {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter a value for feet:");
double d = input.nextDouble();
double valueForFeet = d * 100;
System.out.println("valueforfeet is " + valueForFeet + "In ValueForFeet");
}
}
P64页2.4题将磅转换为千克
package cn.edu.www;
import java.util.Scanner;
public class BangKeShu {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter a number of pound:");
double a = input.nextDouble();
double NumberOfPound= 0.454*a;
System.out.println("NumberOfPound is" + NumberOfPound +"inNumberOfPound");
}
}
P64页2.5题计算小费
package cn.edu.www;
import java.util.Scanner;
public class XiaoFei {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter a number of expenditure");
double expenditure = input.nextDouble();
double tip = expenditure * 0.15;
System.out.println("tip" + tip + "tip");
double amount = expenditure + tip;
System.out.println("amount is " + amount + "in amount");
}
}
第64页2.6题求一个整数各位数的和
package cn.edu.www;
import java.util.Scanner;
public class NumBer {
//此题完成了一半;
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int y = 932;
int z = 14;
int x1 = y %10;
System.out.println("Enter a number 0 and 1000 e.g. :");
double a = input.nextDouble();
double Number = a-y;
System.out.println("x1 is" + x1 + "in x1");
System.out.println("number is" + Number +"in number" );
}
}
第64页第2.7题 求年数
package cn.edu.www;
import java.util.Scanner;
public class TiMe {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter the number of minutes e.g.10,0000,0000:");
double NumberOfMintues = input.nextDouble();
double year = 365;
double day = 24;
double Second = 60;
//365*24*60=525600;
double a = year * day * Second;
//1000000000/525600;
double b = NumberOfMintues / a;
/*10亿取模/365*24*60
* 24*60
*/
double year2 = NumberOfMintues%(365*24*60)/(24*60);
System.out.println("the b is " + b +"and day is" + year2);
第64页2.8题 格林尼治标准时间
package cn.edu.www;
import java.util.Scanner;
public class ShiJianBianLiang {
private static int totalMilliseconds;
public static void main(String[] args) {
// 从午夜开始的总毫秒数;
// Obtian the total milliseconds since midnight, jan 1, 1970
Scanner input = new Scanner(System.in);
long totalMilliseconds = System.currentTimeMillis();
//从午夜开始的总秒数;
// Obtian the total seconds since midnight, jan 1, 1970
long totalSeconds = totalMilliseconds / 1000;
//计算小时内分钟内的当前秒数;
// Compute the current seconds in the minute in the hour
long currentSecond = totalSeconds % 60;
//获得总分钟数
// Obtain the total minutes
long totalMinutes = totalSeconds / 60;
//以小时为单位计算当前分钟;
// Compute the current minute in the hour
long currentMinute = totalMinutes % 60;
//获得总小时数;
// obtain the total hours
long totalHours = totalMinutes / 60;
//计算当前小时数;
// compute the current hour
long currentHour = totalHours % 24;
System.out.println("Enter the time zone offset区域偏移 to GMT -5");
double GMT = input.nextDouble();
GMT = -5;
//显示结果;
// display results
System.out.println("Current time is" + currentHour + ":"
+ currentMinute + ":" + currentSecond + "GMT");
计算平均值
package cn.edu.www;
import java.util.Scanner;
public class ComputeAverage {
//输入一个函数
public static void main(String[] args) {
//创建一个Scanner对象
Scanner input = new Scanner(System.in);
//用户输入3个数字
System.out.println("用户输入3个数字");
double number1 = (10.5);
double number2 = (11);
double number3 = (11.5);
//计算平均值
double average = (number1 + number2 + number3 )/3;
//打印并显示结果
System.out.println("The average of " + number1 +" " + number2 + " " + number3 + " is " + average);
}
}