62,614
社区成员
发帖
与我相关
我的任务
分享
public class GeShui {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// 非负浮点数判断
String regex = "^\\d+(\\.\\d+)?$";
int a = 0;
String str = sc.next();
Pattern pat = Pattern.compile(regex);
Matcher mat = pat.matcher(str);
boolean rs = mat.find();
if(!rs){
System.out.println("请输入合法数值。");
}else{
Double i = Double.parseDouble(str);
if(i-3500<=0){
a = 0;
}else if (i - 3500 <= 1500) {
a = 1;
} else if (i - 3500 <= 4500) {
a = 2;
} else if (i - 3500 <= 9000) {
a = 3;
} else if (i - 3500 <= 35000) {
a = 4;
} else if (i - 3500 <= 55000) {
a = 5;
} else if (i - 3500 <= 80000) {
a = 6;
} else {
a = 7;
}
switch (a) {
case 1:
System.out.println((i - 3500) * 0.03);
break;
case 2:
System.out.println((i - 3500) * 0.10 - 105);
break;
case 3:
System.out.println((i - 3500) * 0.20 - 555);
break;
case 4:
System.out.println((i - 3500) * 0.25 - 1005);
break;
case 5:
System.out.println((i - 3500) * 0.30 - 2755);
break;
case 6:
System.out.println((i - 3500) * 0.35 - 5505);
break;
case 7:
System.out.println((i - 3500) * 0.45 - 13505);
break;
default:
System.out.println("0");
}
}
}
}
package test;
import java.util.Scanner;
public class Scan {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入二次的系数");
int a = sc.nextInt();
System.out.println("请输入一次的系数");
int b = sc.nextInt();
System.out.println("请输入常数");
int c = sc.nextInt();
System.out.println("请输入右边等号的常数");
int d = sc.nextInt();
double x = 0;
if(a*x*x+b*x+c==d){
System.out.println(x);
}
}
}
第四题。package test;
import java.util.Scanner;
public class Scan {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("输入工资:");
String str = sc.nextLine();
int money = Integer.parseInt(str);
int b = money - 3500;
int account = 0;
if (b > 0 && b < 1500) {
account += b * 0.03;
} else if (b > 0 && b < 4500) {
account += 1500 * 0.03 + (b - 1500) * 0.1;
} else if (b > 0 && b < 9000) {
account += 1500 * 0.03 + 3000 * 0.1 + (b - 4500) * 0.2;
} else if (b > 0 && b < 35000) {
account += 1500 * 0.03 + 3000 * 0.1 + 4500 * 0.2 + (b - 9000)
* 0.25;
} else if (b > 0 && b < 55000) {
account += 1500 * 0.03 + 3000 * 0.1 + 4500 * 0.2 + 26000 * 0.25
+ (b - 35000) * 0.3;
} else if (b > 0 && b < 80000) {
account += 1500 * 0.03 + 3000 * 0.1 + 4500 * 0.2 + 4500 * 0.25 + 26000*0.25
+ 20000*0.3 +(b - 80000) * 0.35;
} else if (b > 0 && b >= 80000) {
account += 1500 * 0.03 + 3000 * 0.1 + 4500 * 0.2 + 4500 * 0.25
+ (b - 35000) * 0.3;
}
System.out.println(account);
}
}
不懂什么速算扣除数,楼主自己适当加一下,第三题
public class GeShui {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = 0;
int i = sc.nextInt();
if(i-3500<=0){
a = 0;
}else if (i - 3500 <= 1500) {
a = 1;
} else if (i - 3500 <= 4500) {
a = 2;
} else if (i - 3500 <= 9000) {
a = 3;
} else if (i - 3500 <= 35000) {
a = 4;
} else if (i - 3500 <= 55000) {
a = 5;
} else if (i - 3500 <= 80000) {
a = 6;
} else {
a = 7;
}
switch (a) {
case 1:
System.out.println((i - 3500) * 0.03);
break;
case 2:
System.out.println((i - 3500) * 0.10 - 105);
break;
case 3:
System.out.println((i - 3500) * 0.20 - 555);
break;
case 4:
System.out.println((i - 3500) * 0.25 - 1005);
break;
case 5:
System.out.println((i - 3500) * 0.30 - 2755);
break;
case 6:
System.out.println((i - 3500) * 0.35 - 5505);
break;
case 7:
System.out.println((i - 3500) * 0.45 - 13505);
break;
default:
System.out.println("0");
}
}
}
package test;
import java.util.Scanner;
public class Scan {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("输入数字:");
String str = sc.nextLine();
System.out.println("输入运算符:");
String[] obj = str.split(" ");
String arr = sc.nextLine();
int account = 0;
if("*".equals(arr)){
account = Integer.parseInt(obj[0])*Integer.parseInt(obj[1]);
}else if("/".equals(arr)){
account = Integer.parseInt(obj[0])/Integer.parseInt(obj[1]);
}else if("+".equals(arr)){
account = Integer.parseInt(obj[0])+Integer.parseInt(obj[1]);
}else if("-".equals(arr)){
account = Integer.parseInt(obj[0])-Integer.parseInt(obj[1]);
}
System.out.println(account);
}
}
第二题。package test;
import java.util.Scanner;
public class Scan {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
String[] arr = str.split(" ");
int account = 0;
for(int i=0;i<arr.length;i++){
account += Integer.parseInt(arr[i]);
}
System.out.println(account);
}
}
第一题。
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println(sc.nextInt() + sc.nextInt());
//System.out.println(sc.nextInt() * sc.nextInt());
}
2
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// System.out.println(sc.nextInt() + sc.nextInt());
System.out.println(sc.nextInt() * sc.nextInt());
}