Demo01-31

public class Demo01 {
    public static void main(String[] args) {
        System.out.println((9.5 * 4.5 - 2.5 * 3) / (45.5 - 3.5 ));
    }
}
``

```java
public class Demo02 {
    public static void main(String[] args) {
        System.out.println(4.0 * (1.0 - 1.0 / 3.0 + 1 / 5 - 1 / 7 + 1 / 9 - 1 / 11));
        System.out.println(4.0 * (1.0 - 1.0 / 3.0 + 1 / 5 - 1 / 7 + 1 / 9 - 1 / 11 + 1 / 13));
    }
}
public class Demo03 {
    public static void main(String[] args) {
        System.out.println( 2 * 5.5 * 3.14);
        System.out.println( 5.5 * 5.5 * 3.14 ); 
    }
}
public class Demo04 {
    public static void main[String ()args] {
        System.out.print(" (14*1.6) / 45.5/60 ")
    }
}
`

```java
public class Demo05 {
    public static void main(String [] args) {
        System.out.println((24 * 1.6 / (35 + 3600 + 2400) )* 60 * 60 );
    }
}
public class Demo06 {
    public static void main(String [] args) {
        System.out.println((44.5 * 0.55 - 50.2 * 5.9) / (3.4 * 0.55 - 50.2 * 2.1));
        System.out.println((3.4 * 5.9 - 44.5 * 2.1 ) / (3.4 * 0.55 - 50.2 * 2.1));
    }
}
public class Demo07 {
    public static void main (String [] args ) {
        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 ; //对总小时数取余获得当前的小时数
            System.out.print(Hours + " : " + Minutes + " : " + Seconds );
    }
}
import java.util.Scanner;
public class Demo08 {
    public static void main(String [] args) {
        Scanner in = new Scanner(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;
public class Demo09 {
    public static void main(String[] args) {
        Scanner in = new Scanner(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;
public class Demo10 {
    public static void main(String[] args) {
        Scanner in = new Scanner(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;
public class Demo11 {
    public static void main (String [] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入一个0-1000的数: ");
        int number = scanner.nextInt();
        int g = number % 10; //对number除10取余获得个位
        number = number / 10;//对number除10
        int s = number % 10;//对number除10取余获得十位
        number = number / 10;//对number除10
        int 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;
public class Demo12 {
    public static void main (String [] args ) {
        Scanner in = new Scanner(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 );
        }else if ( H < 0 ) {
            H = H + 24 ;
            System.out.print(H + " : " + Minutes + " : " + Seconds );
        }else {
            System.out.print(H + " : " + Minutes + " : " + Seconds );
        }
    }
}
import java.util.Scanner;
public class Demo13 {
    public static void main(String[] args) {
        Scanner in = new Scanner(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;
public class Demo13 {
    public static void main(String[] args) {
        Scanner in = new Scanner(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;
public class Demo14{
    public static void main(String[] args){
      Scanner in = new Scanner(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;
public class Demo15 {
    public static void main (String [] args) {
        Scanner in = new Scanner(System.in);
        System.out.print(" 请输入第一个点的坐标 : ");
        double x1 = in.nextDouble();//从输入中获得的信息赋值
        double y1 = in.nextDouble();//从输入中获得的信息赋值
        System.out.print(" 请输入第二个点的坐标 : ");
        double x2 = in.nextDouble();//从输入中获得的信息赋值
        double y2 = in.nextDouble();//从输入中获得的信息赋值
        double distance = Math.pow ( Math.pow ( x2 - x1 , 2 ) + Math.pow ( y2 - y1 , 2 ) ,0.5);
        System.out.print(distance);
    }
}
import java.util.Scanner;
public class Demo16 {
    public static void main(String[] args) {
        Scanner in = new Scanner(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;
public class Demo17 {
    public static void main(String[] args) {
        Scanner in = new Scanner(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("瘦");
        }else if (18.5 <= BMI && BMI <= 25.0) {
            System.out.println("正常");
        }else if (25.0 <= BMI && BMI <= 31.0) {
            System.out.println("过重");
        }else {
            System.out.println("肥胖");
        } 
    }
}

import java.util.Scanner;
import java.util.Random;
public class Demo19{
    public static void main(String[] args){
        Random random = new Random();
        int num = random.nextInt(90)+10; // 生成随机整数        
        Scanner in = new Scanner(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美元");
        }else if(a1 == num2 & a2 == num1){
            System.out.print("中奖,3 000美元");
        }else if(a1 == num1 || a1 == num2 || a2 == num1 || a2 == num2){
            System.out.print("中奖,1 000美元");
        }else{
            System.out.print("未中奖");
        }
    }
}

import java.util.Scanner;
public class Demo20 {
    public static void main (String [] args ) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enater a,b,c  : " );
        double a = in.nextDouble();//从输入获得信息赋值给a
        double b = in.nextDouble();//从输入获得信息赋值给b
        double c = in.nextDouble();//从输入获得信息赋值给c
        double delt = b * b - ( 4 * a * c );//delt
        if (delt > 0) {//有两解delt大于0
            double x1 = ( -b + Math.sqrt( delt )) / (2 * a);
            double x2 = ( -b - Math.sqrt( delt )) / (2 * a);
            System.out.print("Has two roots "  + x1  + x2);
        }else if (delt == 0) {//有一解delt等于0
            double x = -b / (2 * a);
            System.out.printf("Has one root " + x);    
        }else {//无解
            System.out.printf("Has no real root ");    
        }
    }
}
import java.util.Scanner;
public class Demo21 {
    public static void main(String[] args) {
        Scanner in = new Scanner(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;
public class Demo22{
    public static void main(String[] args){
        Scanner in = new Scanner(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;
public class Demo23 {
    public static void main (String[] args) {
        Scanner in = new Scanner(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;
public class Demo24{
    public static void main(String[] args){
        Random random = new Random();
        int num = random.nextInt(3)+0; // 生成随机整数(0,2)
        Scanner in = new Scanner(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");
        }else if(num == 1 & num1 == 1){
            System.out.print("The computer is rock .You are is rock .It is a draw");
        }else if(num == 2 & num1 == 2){
            System.out.print("The computer is paper .You are is paper .It is a draw");
            //电脑胜
        }else if(num == 0 & num1 == 2){
            System.out.print("The computer is scissor .You are is paper .computer won");
        }else if(num == 1 & num1 == 2){
            System.out.print("The computer is rock .You are is scissor .computer won");
        }else if(num == 2 & num1 == 1){
            System.out.print("The computer is paper .You are is rock .computer won");
            //人胜
        }else if(num == 0 & num1 == 1){
            System.out.print("The computer is scissor .You are is rock .You won");
        }else if(num == 1 & num1 == 2){
            System.out.print("The computer is rock .You are is paper .You won");
        }else if(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;
public class Demo25{
    public static void main(String[] args){
        Scanner in = new Scanner(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;
        }else if(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;
public class Demo26{
    public static void main(String[] args){
        Scanner in = new Scanner(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("在圆上");
        }else if(d > r){
            System.out.print("在圆外");
        }else{
            System.out.print("在圆内");
        }
    }
}

import java.util.Scanner;
public class Demo27{
    public static void main(String[] args){
        Scanner in = new Scanner(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("边上");
        }else if(x > sl & y > cl){
            System.out.print("内");
        }else{
            System.out.print("外");
        }
    }
}

import java.util.Scanner;
public class Demo28 {
    public static void main (String [] args) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter a point: ");
        double x = in.nextDouble();//从输入的点中获取第一个值 并赋予x 由于坐标点为小数所以需要用double
        double y = in.nextDouble();//从输入的点中获取第二个值 并赋予y 由于坐标点为小数所以需要用double
        if (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;
public class Demo29{
    public static void main(String [] args) {
    Scanner in = new Scanner(System.in);
    System.out.print("第一个矩形的信息 :");
    double x1=in.nextDouble();
    double y1=in.nextDouble();
    double h1=in.nextDouble();
    double w1=in.nextDouble();
    System.out.print("第二个矩形的信息 : ");
    double x2=in.nextDouble();
    double y2=in.nextDouble();
    double h2=in.nextDouble();
    double w2=in.nextDouble();
    double inXMin=x1-(w1-w2) / 2;
    double inXMax=x1+(w1-w2) / 2;
    double inYMin=y1-(h1-h2) / 2;
    double inYMax=y1+(h1-h2) / 2;
    double outXMin=x1-(w1+w2) / 2;
    double outXMax=x1+(w1-w2) /2 ;
    double outYMin=y1-(h1-h2) / 2;
    double outYMax=y1+(h1-h2) / 2;
    if (x2 >= inXMin && x2 <= inXMax && y2 >= inYMin && y2<= inYMax ){
        System.out.println("小矩形在大矩形内部 ");
    } else if (x2 <= outXMin || x2 >= outXMax || y2<= outYMin || y2 >= outXMax){
        System.out.println("小矩形在大矩形外部 ");
    }else {
        System.out.println("小矩形和大矩形相交 ");
    }
}
}
import java.util.Scanner;
public class Demo30{
    public static void main(String[] args){
        Scanner in = new Scanner(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内");
        }else if(d <= r0 + r){
            System.out.print("circle2和circle重叠");
        }else{
            System.out.print("circle2在circle外");
        }
    }
}

import java.util.Scanner;
public class Demo31{
    public static void main(String[] args){
        Scanner in = new Scanner(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");
        }else if((num % 5 == 0) || (num % 6 ==0)){
            System.out.print("Is num divisible 5 or 6 ? ture");
        }else if(num % 5 == 0){
            System.out.print("Is num divisible 5 or 6 ,but not both ? ture");
        }else if(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中的任一数整除");
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值