# Exercise the next day

### That is: import java.util.Scanner; (If the program uses another class in the util directory, the source code of the import package can be written as import java.util. *)

```import java.util.Scanner;

class Excercise1{
public static void main (String[] args){
Scanner input =new Scanner(System.in);
//Input Celsius Temperature
System.out.println("Input Celsius Temperature:");
double c=input.nextDouble();
//Convert Celsius to Fahrenheit
double f=0.0;
f=(9 / 5.0) * c + 32;
System.out.println("The input Celsius to Fahrenheit temperature is:"+f);
}
}```

```import java.util.Scanner;

class Excercise2{
public static void main(String[] args){
double p=3.1415;
Scanner input =new Scanner(System.in);
//Input radius and height
System.out.println("Please enter radius and height");
double r=input.nextDouble();
double h=input.nextDouble();
//Calculate volume v
double v=r*r*p*h;
System.out.println("The volume of a cylinder is"+v);
}
}```

### That is, an integer is the result of dividing two numbers, such as 9/5=1 5/4=0. When decimals appear on either side of the division sign, the result is what we learn every day, such as 5/10.0=0.5/2=2.5.Remainder operations are quotient operations compared to integer division operations)

```import java.util.Scanner;

class Excercise3 {
public static void main(String[] args){
//Input Scanner class is called first
Scanner input =new Scanner(System.in);
int sum,num1,num2,num3;
//Enter a number from the console
System.out.println("Enter a 0~1000 Number within");
int num=input.nextInt();
//Separate the digits of this number from the digits of 10 and 100
/*
This number is divided into three cases
1.If the number is a number of digits, the direct output (that is, the number is the sum)
2.If the number is a ten digit number, dividing the ten digits by the whole is the number on the ten digits
The remainder, that is, the number in each of you, is the remainder.
3.Ditto
*/
//If the number is a single digit
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("The sum of the digits, the ten digits and the hundred is"+sum);
}
}```

```import java.util.Scanner;

class Excercise4 {
public static void main(String[] args){
//Define an offset excursion
int excursion;
//Define the total time (time in milliseconds), define the current second (timem), define the current minute (timef), and define the current time (times)
long time,timem,timef,times;
//Total Import Time
time = System.currentTimeMillis();
//Calculate the current hour, minute, second
timem = time / 1000 % 60;
timef = time/ 1000 / 60 % 60;
times = time / 1000 / 60 / 60 % 24;
//Input Time Offset
System.out.print("Time offset is:");
Scanner input = new Scanner(System.in);
excursion = input.nextInt();
//Calculate offset hours
times = (times + excursion + 24) % 24;
System.out.println("The offset area time is "
+ times + ":" + timef + ":" + times);

}
}```

```class Excercise5{
public static void main(String[] args){
int i;
//Defined as floating point because annual interest rates are decimal
double j=(1+0.05/12),money=0;
//Save 100 yuan in the first month, the interest rate is j, 100*j, and so on
for(i=1;i<7;i++){
money=money+100;
money=money*j;
}
System.out.println("The balance of the account after six months is:"+money);
}
}```

### This topic relatively simply adds a function to call Math.pow(x,0.5) which is square to x, that is, when 0.5 in parentheses changes, that is, the original function changes, 0.5~2 squares the unknown quantity

```import java.util.Scanner;

class Excercise6 {
public static void main(String[] args){
//Define x1, x2, y1, y2
//Prompt user for coordinates of two points
Scanner input=new Scanner(System.in);
System.out.println("Please enter them separately 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("The distance between two points is:"+result);
}
}```

```import java.util.Scanner;

class Excercise7 {
public static void main(String[] args){
Scanner input=new Scanner(System.in);
//Prompt for x1,x2,x3,y1,y2,y3;
System.out.println("Input separately 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("The area of a triangle is:"+ss);
}
}```

Four original articles have been published, 0 won and 139 visited

Keywords: Java

Added by oolongdavies on Sat, 08 Feb 2020 04:11:11 +0200