The next day exercises

Fahrenheit is converted to degrees Celsius

This question is most important is the console input sentence Scanner

With the knowledge learned view, then Scanner is a class title in the input object is a class Scanner

Then, input object called nextDouble () This method

This is the format of the input sentence

Scanner Object = new Scanner (System.in);

int (double) = variable objects .nextInt (Double) ();

More important is that when a program calls this method after all methods should Scanner class that is the class of a "package" to feed in

Namely: import java.util.Scanner; (if the program used in another class util directory, the leader packet can be written as source code import java.util *.)

import java.util.Scanner;

class Excercise1{
    public static void main (String[] args){
        Scanner input =new Scanner(System.in);
        //输入摄氏温度
        System.out.println("输入摄氏温度:");
        double c=input.nextDouble();
        //摄氏温度转为华氏温度
        double f=0.0;
        f=(9 / 5.0) * c + 32;
        System.out.println("输入的摄氏温度转化为华氏温度是:"+f);
    }
}

 

import java.util.Scanner;

class Excercise2{
    public static void main(String[] args){
        double p=3.1415;
        Scanner input =new Scanner(System.in);
        //输入半径和高
        System.out.println("请输入半径和高");
        double r=input.nextDouble();
        double h=input.nextDouble();
        //算出体积v
        double v=r*r*p*h;
        System.out.println("圆柱体的体积是"+v);
    }
}

The problem is that the study of knowledge and understanding of the divisible modulo

I.e., (i.e., divides the result obtained by dividing two numbers is an integer, e.g. 9/5 = 15/4 = 0, except when both sides of the results obtained i.e. a decimal number appears our everyday starting learned, for example 5 / 10.0 = 5 0.5 / 2 = 2.5. compared integer division, modulo arithmetic is modulo quotient)

import java.util.Scanner;

class Excercise3 {
    public static void main(String[] args){
        //先调用输入的Scanner类
        Scanner input =new Scanner(System.in);
        int sum,num1,num2,num3;
        //从控制台输入一个数
        System.out.println("输入一个0~1000以内的数");
        int num=input.nextInt();
        //将这个数字的个位、十位、百位分开
        /*
        这个数字分为三种情况
        1.如果该数字是个位数,则直接输出结果(即数字即为和)
        2.如果该数字是十位数,求出十位数即整除除十得到的结果即十位上的数
        取余该数即各位上的数便是余数
        3.同上
         */
        //如果该数字为个位数
        if (num<10){
            sum=num;
        }else if(num<100||num>10){
            num1=num%10;
            num2=num/10;
            sum=num1+num2;
        }else{
            num1=num%10;
            num2=num%100/10;
            num3=num/100;
            sum=num1+num2+num3;
        }
        System.out.println("该数字的个位、十位、百位的和是"+sum);
    }
}

import java.util.Scanner;

class Excercise4 {
    public static void main(String[] args){
        //定义一个偏移量excursion
        int excursion;
        //定义总时间(按照毫秒计算的time)、定义当前秒(timem)、定义当前分(timef)、定义当前时(times)
		long time,timem,timef,times;
		//导入总时间
		time = System.currentTimeMillis();
        //计算当前时、分、秒
		timem = time / 1000 % 60;
		timef = time/ 1000 / 60 % 60;
		times = time / 1000 / 60 / 60 % 24;
		//输入时间偏移量
		System.out.print("时间偏移量为:");
		Scanner input = new Scanner(System.in);
		excursion = input.nextInt();
		//计算偏移的小时
		times = (times + excursion + 24) % 24;
		System.out.println("偏移地区时间为 "
							+ times + ":" + timef + ":" + times);
 
    }
}

class Excercise5{
    public static void main(String[] args){
        int i;
        //因为年利率涉及小数所以定义为浮点型
        double j=(1+0.05/12),money=0;
        //第一个月存入100元,利率为j,即100*j,以此类推
        for(i=1;i<7;i++){
            money=money+100;
            money=money*j;
        }
        System.out.println("六个月后账户的余额为:"+money);
    }
}

The opposite problem is just added for a function call Math.pow i.e. (x, 0.5) which is a function of the square root of x, i.e. when the change brackets 0.5, that is the original function is changed, 2 is 0.5 to squaring unknowns

import java.util.Scanner;

class Excercise6 {
    public static void main(String[] args){
        //定义x1、x2、y1、y2
        //提示用户输入两个点的坐标
        Scanner input=new Scanner(System.in);
        System.out.println("请分别输入x1,x2,y1,y2:");
        double x1=input.nextDouble();
        double x2=input.nextDouble();
        double y1=input.nextDouble();
        double y2=input.nextDouble();
        double a=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);
        double result=Math.pow(a,0.5);
        System.out.println("两点之间的距离是:"+result);
    }
}

import java.util.Scanner;

class Excercise7 {
    public static void main(String[] args){
        Scanner input=new Scanner(System.in);
        //提示输入x1,x2,x3,y1,y2,y3;
        System.out.println("分别输入x1,x2,x3,y1,y2,y3:");
        double x1=input.nextDouble();
        double x2=input.nextDouble();
        double x3=input.nextDouble();
        double y1=input.nextDouble();
        double y2=input.nextDouble();
        double y3=input.nextDouble();5
        double s,s1,s2,s3;
        s1=Math.pow((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1),0.5);
        s2=Math.pow((x3-x1)*(x3-x1)+(y3-y1)*(y3-y1),0.5);
        s3=Math.pow((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2),0.5);
        s=(s1+s2+s3)/2;
        double ss=Math.pow(s*(s-s1)*(s-s2)*(s-s3),0.5);
        System.out.println("三角形的面积是:"+ss);
    }
}

 

Released four original articles · won praise 0 · Views 160

Guess you like

Origin blog.csdn.net/knapweed_/article/details/104219015