}
}
[]( )2.计算小费
===================================================================
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200611105153642.png)
import java.util.Scanner;
public class Text2 {
public static void main(String[] args) {
System.out.print("请输入一笔费用和酬金率:");
Scanner s=new Scanner(System.in);
//读入费用
double tips=s.nextDouble();
//读入酬金率
double rate=s.nextDouble();
//计算酬金
double Remuneration=(tips*rate)/100+(tips*rate)%10;//计算酬金
//计算总费用
double cost=tips+Remuneration;
System.out.println("酬金为:"+Remuneration+"\t"+"总费用为:"+cost);
}
}
[]( )3.个位数和
===================================================================
![在这里插入图片描述](https://img-blog.csdnimg.cn/202006111053228.png)
import java.util.Scanner;
public class Text3 {
public static void main(String[] args) {
System.out.println("请输入一个0~1000的数字:");
Scanner s = new Scanner(System.in);
int i = s.nextInt();
if (i > 0 && i < 1000) {
//取百位
int x=i/100;
//取十位
int y=i/100%10;
//取个位
int z=i%10;
System.out.println("个位数相加和为:"+x+y+z);
}else{
System.out.println("对不起,您输入的数字有误!");
}
}
}
[]( )4.复利值
==================================================================
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200611105404362.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1pwX2luc2lzdA==,size_16,color_FFFFFF,t_70)
import java.util.Scanner;
public class Text4 {
public static void main(String[] args) {
System.out.println("请输入存入的金额以及要查询余额月份:");
Scanner s=new Scanner(System.in);
int dollar=s.nextInt();
int month=s.nextInt();
double cost=0.0;
for(int i=1;i<=month;i++){
cost=(dollar+cost)*(1+0.00417);
System.out.println("第"+i+"个月后帐户的金额为:"+cost);
}
}
}
[]( )5.实现二进制转化十进制
=========================================================================
import java.util.Scanner;
public class Text5 {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
System.out.print("输入一个二进制数 ");
int binaryNumber = s.nextInt();
int decimal = 0;
int p = 0;
while (true) {
if (binaryNumber == 0) {
break;
} else {
int temp = binaryNumber % 10;
decimal += temp * Math.pow(2, p);
binaryNumber = binaryNumber / 10;
p++;
}
}
System.out.println("十进制数为:"+decimal);
}
}
[]( )6.实现十进制转化二进制
=========================================================================
import java.util.Scanner;
public class Text6 {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
System.out.print("输入一个十进制数 ");
int n = s.nextInt();
String str = "";
while (n != 0) {
str = n % 2 + str;
n = n / 2;
}
System.out.println(str);
}
}
[]( )7.两点距离公式
=====================================================================
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200611105638696.png)
import java.util.Scanner;
import static java.lang.Math.*;
public class Text7 {
public static void main(String[] args) {
System.out.print("请输入x1,y1的值:");
Scanner s=new Scanner(System.in);
double x1=s.nextDouble();
double y1=s.nextDouble();
System.out.print("请输入x2,y2的值:");
double x2=s.nextDouble();