仅供参考,未测试
Question1
package com.kidd.atmtest;
import java.util.Scanner;
public class Question1 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("输入基本运费,货重,距离(均为整数,用,分割):");
String[] ss = scanner.next().split(",");
int p = Integer.parseInt(ss[0]);
int w = Integer.parseInt(ss[1]);
int s = Integer.parseInt(ss[2]);
double d ;
if(s < 250){
d=0 ;
}else if(s < 500){
d=0.02;
}else if(s < 1000){
d=0.05;
}else if(s < 2000){
d=0.08 ;
}else{
d=0.1;
}
System.out.println("总运费f="+(p*w*s*(1-d)));
}
}
Question2
package com.kidd.atmtest;
import java.util.Scanner;
public class Question2 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入x:");
int x = scanner.nextInt();
int y ;
if(x<0){
y=-1;
}else if (x >0){
y=1;
}else{
y=0;
}
System.out.println("y="+y);
}
}
Question3
package com.kidd.atmtest;
import java.util.Scanner;
public class Question3 {
public static void main(String[] args) {
int index = 0;
Scanner scanner = new Scanner(System.in);
boolean end = false;
while (!end) {
System.out.print("请输入卡号,密码:");
scanner.next();
index++;
System.out.print("账号或密码错误次数" + index + ",");
if (index >= 3) {
System.out.println("吞卡");
end = true;
} else {
System.out.println("请重新输入.");
}
}
}
}
Question4
package com.kidd.atmtest;
import java.util.Scanner;
public class Question4 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("输入一个整数:");
String string = scanner.next();
for (int i = 0, k = string.length(); i < k; i++) {
System.out.println(string.charAt(i));
}
}
}
Question5
package com.kidd.atmtest;
import java.util.Random;
import java.util.Scanner;
public class Question5 {
public static void main(String[] args) {
int i = new Random().nextInt(40) + 60;
boolean end = false;
int n;
int index = 1;
Scanner scanner = new Scanner(System.in);
while (!end) {
System.out.print("请输入你猜的结果:");
n = scanner.nextInt();
if (n > i) {
System.out.println("大了");
index++;
} else if (n < i) {
System.out.println("小了");
index++;
} else {
end = true;
}
}
System.out.print("猜对了,一共猜了" + index + "次,你是");
if (index < 5) {
System.out.print("天才.");
} else {
System.out.print("笨蛋.");
}
}
}
Question6
package com.kidd.atmtest;
import java.util.Scanner;
public class Question6 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入要打印的元素个数:");
int n = scanner.nextInt();
if (n < 1) {
System.out.println("无输出结果");
}
if (n >= 1) {
System.out.print("1");
}
if (n >= 2) {
System.out.print(",2");
}
if (n > 2) {
int f1 = 1;
int f2 = 2;
int sum;
for (int i = 3; i <= n; i++) {
sum = f1 + f2;
System.out.print("," + (f1 + f2));
f1 = f2;
f2 = sum;
}
}
}
}