import java.util.Scanner;publicclassDemo08{publicstaticvoidmain(String [] args){
Scanner in =newScanner(System.in);
System.out.print("请输入一个值: ");double a = in.nextDouble();int b =(int)(a *100);
System.out.println(" 一分币的个数 = "+ b);//第一题int c = b /100;
System.out.println(" 一美元的个数 = "+ c);int d = b %100;
System.out.println(" 剩余一分币的个数 = "+ d);int e = d /25;
System.out.println(" 2角5分币的个数 = "+ e);int f = d %25;
System.out.println(" 剩余一分币的个数 = "+ f);int g = f /10;
System.out.println(" 一角币的个数 = "+ g);int h = f %10;
System.out.println(" 剩余一分币的个数 = "+ h);int j = h /5;
System.out.println(" 5分币的个数 = "+ j);int i = h %5;
System.out.println(" 剩余一分币的个数 = "+ i);
System.out.println(c + e + g + j + i);}}
import java.util.Scanner;publicclassDemo09{publicstaticvoidmain(String[] args){
Scanner in =newScanner(System.in);
System.out.print("Enter a degree in Celsius:");double tmp = in.nextDouble();//输入摄氏double Fahrenheit = tmp *(9.0/5)+32;//计算华氏
System.out.printf("%f Celsius is %f Fahrenheit", tmp, Fahrenheit);}}
import java.util.Scanner;publicclassDemo10{publicstaticvoidmain(String[] args){
Scanner in =newScanner(System.in);
System.out.print("Enter the radius and length of a cylinder:");double r = in.nextDouble();//输入半径double h = in.nextDouble();//输入高double area = r * r *3.1415;//计算面积double volume = area * h;//计算体积
System.out.printf("The area is %f", area);
System.out.printf("The volume is %f", volume);}}
import java.util.Scanner;publicclassDemo11{publicstaticvoid main (String [] args){
Scanner scanner =newScanner(System.in);
System.out.print("请输入一个0-1000的数: ");int number = scanner.nextInt();int g = number %10;//对number除10取余获得个位
number = number /10;//对number除10int s = number %10;//对number除10取余获得十位
number = number /10;//对number除10int b = number %10;//对number除10取余获得百位
number = number /10;//对number除10
System.out.print(" The sum of the number is ");
System.out.print(g + s + b);}}
import java.util.Scanner;publicclassDemo12{publicstaticvoid main (String [] args ){
Scanner in =newScanner(System.in);
System.out.print("Enter the time zone offset to GMT : ");long p = in.nextInt();long totalMilliseconds = System.currentTimeMillis();//获得总毫秒数long totalSeconds = totalMilliseconds /1000;//获得总的秒数long Seconds = totalSeconds %60;//对总秒数取余获得当前的秒数long totalMinutes = totalSeconds /60;//获得总的分钟数long Minutes = totalMinutes %60;//对总分钟数取余获得当前的分钟数long totalHours = totalMinutes /60;//获得总小时数long Hours = totalHours %24;//对总小时数取余获得当前的小时数long H = p + Hours ;if( H >=24){
H = H -24;
System.out.print(H +" : "+ Minutes +" : "+ Seconds );}elseif( H <0){
H = H +24;
System.out.print(H +" : "+ Minutes +" : "+ Seconds );}else{
System.out.print(H +" : "+ Minutes +" : "+ Seconds );}}}
import java.util.Scanner;publicclassDemo13{publicstaticvoidmain(String[] args){
Scanner in =newScanner(System.in);
System.out.print("Enter the amount of water in kg:");double m = in.nextDouble();//输入重量
System.out.print("Enter the initial temperature:");double a = in.nextDouble();//输入起始温度
System.out.print("Enter the final temperature:");double b = in.nextDouble();//输入结束温度double Q = m *(b - a)*4184;//计算热量
System.out.printf("The energy needed is %f", Q);}}
import java.util.Scanner;publicclassDemo13{publicstaticvoidmain(String[] args){
Scanner in =newScanner(System.in);
System.out.print("Enter the amount of water in kg:");double m = in.nextDouble();//输入重量
System.out.print("Enter the initial temperature:");double a = in.nextDouble();//输入起始温度
System.out.print("Enter the final temperature:");double b = in.nextDouble();//输入结束温度double Q = m *(b - a)*4184;//计算热量
System.out.printf("The energy needed is %f", Q);}}
import java.util.Scanner;publicclassDemo14{publicstaticvoidmain(String[] args){
Scanner in =newScanner(System.in);
System.out.print("Enter the monthly saving amount: ");double money = in.nextDouble();double sum =0;double year =0.05;//计算6个月后账户的总钱数double monRates = year /12;//用循环语句简化程序,计算6个月后账户的总钱数for(int mon =1; mon <7; mon++){
sum =(money + sum)* Math.pow(1+ monRates,1);}
System.out.print(sum);}}
import java.util.Scanner;publicclassDemo16{publicstaticvoidmain(String[] args){
Scanner in =newScanner(System.in);
System.out.print("Enter Three points for a triangle : ");double x1 = in.nextDouble();double y1 = in.nextDouble();double x2 = in.nextDouble();double y2 = in.nextDouble();double x3 = in.nextDouble();double y3 = in.nextDouble();// 根据公式计算 三边以及 s 面积double b1 = Math.sqrt(Math.pow(x2 - x1 ,2)+ Math.pow(y2 - y1 ,2));double b2 = Math.sqrt(Math.pow(x3 - x1 ,2)+ Math.pow(y3 - y1 ,2));double b3 = Math.sqrt(Math.pow(x3 - x2 ,2)+ Math.pow(y3 - y2 ,2));double s =(b1 + b2 + b3)/2;double area = Math.sqrt(s *(s - b1)*(s - b2)*(s - b3));
System.out.printf("The area of the triangle is %f", area);}}
import java.util.Scanner;publicclassDemo17{publicstaticvoidmain(String[] args){
Scanner in =newScanner(System.in);
System.out.print("Enter your weight");double w = in.nextDouble();
System.out.print("Enter your height");double h = in.nextDouble();double k = w *0.45359237;// 转化为千克double m = h *0.0254;//转化为化米double BMI = k / m;if(BMI <18.5){
System.out.println("瘦");}elseif(18.5<= BMI && BMI <=25.0){
System.out.println("正常");}elseif(25.0<= BMI && BMI <=31.0){
System.out.println("过重");}else{
System.out.println("肥胖");}}}
import java.util.Scanner;import java.util.Random;publicclassDemo19{publicstaticvoidmain(String[] args){
Random random =newRandom();int num = random.nextInt(90)+10;// 生成随机整数
Scanner in =newScanner(System.in);
System.out.print("输入一个两位数:");int a = in.nextInt();int num1 = num /10;int num2 = num %10;int a1 = a /10;int a2 = a %10;//求出个位与十位if(a == num){
System.out.print("中奖,10 000美元");}elseif(a1 == num2 & a2 == num1){
System.out.print("中奖,3 000美元");}elseif(a1 == num1 || a1 == num2 || a2 == num1 || a2 == num2){
System.out.print("中奖,1 000美元");}else{
System.out.print("未中奖");}}}
import java.util.Scanner;publicclassDemo20{publicstaticvoid main (String [] args ){
Scanner in =newScanner(System.in);
System.out.print("Enater a,b,c : ");double a = in.nextDouble();//从输入获得信息赋值给adouble b = in.nextDouble();//从输入获得信息赋值给bdouble c = in.nextDouble();//从输入获得信息赋值给cdouble delt = b * b -(4* a * c );//deltif(delt >0){//有两解delt大于0double x1 =(-b + Math.sqrt( delt ))/(2* a);double x2 =(-b - Math.sqrt( delt ))/(2* a);
System.out.print("Has two roots "+ x1 + x2);}elseif(delt ==0){//有一解delt等于0double x =-b /(2* a);
System.out.printf("Has one root "+ x);}else{//无解
System.out.printf("Has no real root ");}}}
import java.util.Scanner;publicclassDemo21{publicstaticvoidmain(String[] args){
Scanner in =newScanner(System.in);
System.out.print("Enter a b c d e f :");double a = in.nextDouble();double b = in.nextDouble();double c = in.nextDouble();double d = in.nextDouble();double e = in.nextDouble();double f = in.nextDouble();//赋值double x =((e * d)-(b * f))/((a * d)-(b * c));double y =((a * f)-(e * c))/((a * d)-(b * c));if((a * d)-(b * c)!=0){
System.out.printf("x is %.1f and y is %.1f",x ,y);}else{
System.out.print("无解");}}}
import java.util.Scanner;publicclassDemo22{publicstaticvoidmain(String[] args){
Scanner in =newScanner(System.in);
System.out.print("Enter today's day : ");int day = in.nextInt();
System.out.print("Enter the number of days elapsed since today : ");int number = in.nextInt();int day1 = number %7;//计算出星期数int finallyday = day1 + day;//总的天数
System.out.print("Today is "+ day);
System.out.print(" and the future day is "+ finallyday);}}
import java.util.Scanner;publicclassDemo23{publicstaticvoid main (String[] args){
Scanner in =newScanner(System.in);
System.out.print("Enter a three-digit integer:");int num = in.nextInt();int g = num %10;//求个位int b = num /100;//if(g == b){
System.out.printf("%d is a palidrome", num);}else{
System.out.printf("%d is not a palidrome", num);}}}
import java.util.Scanner;import java.util.Random;publicclassDemo24{publicstaticvoidmain(String[] args){
Random random =newRandom();int num = random.nextInt(3)+0;// 生成随机整数(0,2)
Scanner in =newScanner(System.in);
System.out.print("scissor(0),rock(1),paper(2): ");int num1 = in.nextInt();if(num ==0& num1 ==0){
System.out.print("The computer is scissor .You are is scissor .It is a draw");}elseif(num ==1& num1 ==1){
System.out.print("The computer is rock .You are is rock .It is a draw");}elseif(num ==2& num1 ==2){
System.out.print("The computer is paper .You are is paper .It is a draw");//电脑胜}elseif(num ==0& num1 ==2){
System.out.print("The computer is scissor .You are is paper .computer won");}elseif(num ==1& num1 ==2){
System.out.print("The computer is rock .You are is scissor .computer won");}elseif(num ==2& num1 ==1){
System.out.print("The computer is paper .You are is rock .computer won");//人胜}elseif(num ==0& num1 ==1){
System.out.print("The computer is scissor .You are is rock .You won");}elseif(num ==1& num1 ==2){
System.out.print("The computer is rock .You are is paper .You won");}elseif(num ==2& num1 ==0){
System.out.print("The computer is paper .You are is rock .You won");}else{
System.out.print("Please Enter 0, 1, 2");}}}
import java.util.Scanner;publicclassDemo25{publicstaticvoidmain(String[] args){
Scanner in =newScanner(System.in);
System.out.print("Enter year:(e.g.,2012): ");int year = in.nextInt();//年
System.out.print("Enter month:1-12: ");int m = in.nextInt();//月
System.out.print("Enter the day of the month: 1-31: ");int q = in.nextInt();//某一天int j =(int)Math.ceil(year /100);//世纪int k = year %100;//该世纪的第几年if(m ==1){
m =13;}elseif(m ==2){
m =14;//同时将年份改为前一年}if(m ==13| m ==14){
k -=1;}
System.out.print(k +" ");int h =((q +(26*(m +1)/10)+ k +(k /4)+(j /4)+5* j))%7;//公式
System.out.print("Day of the week is "+ h);}}
import java.util.Scanner;publicclassDemo26{publicstaticvoidmain(String[] args){
Scanner in =newScanner(System.in);
System.out.print("Enter a point with two coordinates:");double x = in.nextDouble();double y = in.nextDouble();double x0 =0;double y0 =0;double r =10;double d = Math.pow((Math.pow((x - x0),2)+Math.pow((y - y0),2)),0.5);//点到圆心的距离if(d == r){//判断位置关系
System.out.print("在圆上");}elseif(d > r){
System.out.print("在圆外");}else{
System.out.print("在圆内");}}}
import java.util.Scanner;publicclassDemo27{publicstaticvoidmain(String[] args){
Scanner in =newScanner(System.in);
System.out.print("Enter a point with two coordinates:");double x = in.nextDouble();double y = in.nextDouble();double sl =5.0;double cl =2.5;//水平距离最小值,垂直距离最小值
x = Math.abs(x);
y = Math.abs(y);//给x,y取绝对值if(x == sl & y == cl){
System.out.print("边上");}elseif(x > sl & y > cl){
System.out.print("内");}else{
System.out.print("外");}}}
import java.util.Scanner;publicclassDemo28{publicstaticvoid main (String [] args){
Scanner in =newScanner(System.in);
System.out.print("Enter a point: ");double x = in.nextDouble();//从输入的点中获取第一个值 并赋予x 由于坐标点为小数所以需要用doubledouble y = in.nextDouble();//从输入的点中获取第二个值 并赋予y 由于坐标点为小数所以需要用doubleif(x >=0&& y>=0&& x<=200&& y<=100){//判断出是否在矩形内部若不在矩形内部直接判断if( y/(200- x )<=0.5){//已知在矩形内部的情况下判断出是否在三角形内部
System.out.print("该点位于矩形内部并且三角形内部");}else{
System.out.print("该点位于矩形内部但并不位于三角形内部");}}else{
System.out.print("该点不位于矩形内部且不位于三角形内部");}}//坐标判断是否在矩形内部//在判段 y/(200 - x)是否<0.5}
import java.util.Scanner;publicclassDemo30{publicstaticvoidmain(String[] args){
Scanner in =newScanner(System.in);
System.out.print("Enter circle1's center x-,y-coordinates,and radius:");double x = in.nextDouble();double y = in.nextDouble();double r = in.nextDouble();
System.out.print("Enter circle2's center x-,y-coordinates,and radius:");double x0 = in.nextDouble();double y0 = in.nextDouble();double r0 = in.nextDouble();double d = Math.pow((Math.pow((x - x0),2)+Math.pow((y - y0),2)),0.5);//计算两圆心间距离if(d <= Math.abs(r - r0)){//判断位置关系
System.out.print("circle2在circle1内");}elseif(d <= r0 + r){
System.out.print("circle2和circle重叠");}else{
System.out.print("circle2在circle外");}}}
import java.util.Scanner;publicclassDemo31{publicstaticvoidmain(String[] args){
Scanner in =newScanner(System.in);
System.out.print("Enter an integer:");int num = in.nextInt();if((num %5==0)&&(num %6==0)){
System.out.print("Is num divisible 5 and 6 ? ture");}elseif((num %5==0)||(num %6==0)){
System.out.print("Is num divisible 5 or 6 ? ture");}elseif(num %5==0){
System.out.print("Is num divisible 5 or 6 ,but not both ? ture");}elseif(num %6==0){
System.out.print("Is num divisible 5 or 6 ,but not both ? ture");}else{
System.out.print("不能被5和6,5或6,5 6中的任一数整除");}}}