计算需要支付的金额
解答:
import java.util.*; public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int n = cin.nextInt();
double s = n * 95; if (s >= 300) { s = s * 0.85; } System.out.printf("%.2f ", s); } }
--------------------题目分割线--------------------
四位数反转
【分析】
首先将四位数读入变量n,然后进行分离。千位等于n/1000,百位等于n/100%10(注意这里取的是商的整数部分),十位数等于n/10%10(这里的%是取余数操作),个位数等于n%10。完整的程序如下:
程序
package Test; import java.util.Scanner; public class Main { public static void main(String[] args) { String num,str; Scanner scan=new Scanner(System.in); for(int i=0;i<5;i++){ num=scan.next(); char a=num.charAt(0); char b=num.charAt(1); char c=num.charAt(2); char d=num.charAt(3); if(d-'0'!=0){ str=String.valueOf(d)+String.valueOf(c)+String.valueOf(b)+String.valueOf(a); System.out.println(str); } else{ str=String.valueOf(c)+String.valueOf(b)+String.valueOf(a); System.out.println(str); }
}
}
}
--------------------题目分割线--------------------
成绩分级管理
学校进行成绩分级管理,取消分数制,改为成绩分级评定。具体办法是:小于60分为E类;60分至70分(不含70分)为D类;70分至80分(不含)为C类;80分至90分(不含)为B类;90分以上为A类。设计一个程序,对输入的成绩进行等价划分。
import java.util.Scanner;
public class Main { public static void main(String[] args) { @SuppressWarnings("resource") Scanner s = new Scanner(System.in); int score;
while (s.hasNext()) { score = s.nextInt(); if (score >= 90 && score <= 100) {
System.out.println("A"); } else if (score >= 80 && score <= 89) { System.out.println("B"); } else if (score >= 70 && score <= 79) { System.out.println("C"); } else if (score >= 60 && score <= 69) { System.out.println("D"); } else if (score >= 0 && score <= 59) { System.out.println("E"); } else { System.out.println("Score is error!"); } } } }
--------------------题目分割线--------------------
Java,Current
time, 2557
显示当前北京时间(十二小时制)如:10:50:34 AM
public class Main { public static void main(String[] args) {
// Obtain the total milliseconds since the midnight, Jan 1, 1970 long totalMilliseconds = System.currentTimeMillis();
// Obtain the total seconds since the midnight, Jan 1, 1970 long totalSeconds = totalMilliseconds / 1000; // Compute the current second in the minute in the hour long currentSecond = totalSeconds % 60;
// Obtain the total minutes
long totalMinutes = totalSeconds / 60;
// Compute the current minute in the hour long currentMinute = totalMinutes % 60; // Obtain the total hours long totalHours = totalMinutes / 60; // Compute the current hour long currentHour = (totalHours) % 24;
// Display results
System.out.print("Current time is " + ((currentHour % 12) + 8) + ":" + currentMinute + ":" + currentSecond);
if (currentHour < 12)
System.out.println(" AM");
else
System.out.println(" PM");
}
}
简单分列式
import java.util.Scanner; public class Main {
public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in);
double a = sc.nextDouble();
if (a > 0) {
System.out.println(1);
}
if (a == 0) {
System.out.println(0);
} if (a < 0) {
System.out.println(-1);
} }
}
--------------------题目分割线--------------------
停车场收费
import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner Me = new Scanner(System.in);
for (int i = 0; ; i++) { double a = Me.nextDouble(); if (a <= 3) { System.out.printf("5.00 ");
} else if (((a - 3) * 2 + 5) > 40) {
System.out.printf("40.00 ");
} else {
System.out.printf("%.2f ", (a - 3) * 2 + 5); } }
}
}
与7无关的数
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws Exception {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int i;
long sum = 0;
for (i = 1; i <= n; i++) {
if (i % 7 == 0 || i % 10 == 7 || i / 10 == 7) { continue; } sum = sum + i * i; }
System.out.println(sum); } }
--------------------题目分割线--------------------
import java.util.Scanner; public class Main { public static void main(String args[]) { Scanner scan = new Scanner(System.in);
int n = scan.nextInt(); for (int i = 0; i <= n; i++) { double s = scan.nextDouble(); double tw = s / 1.2; double tb = 27 + s / 3 + 23; if (tw > tb) System.out.println("Bike"); else if (tw < tb)
System.out.println("Walk");
else System.out.println("All");
} }
}
--------------------题目分割线--------------------
点和正方形的关系
import java.util.Scanner;
public class Main { public static void main(String[] args) throws Exception { Scanner input = new Scanner(System.in); int[] arr = new int[100]; for (int i = 0; i < 100; i++) {
int a = input.nextInt(); int b = input.nextInt();
if ((a >= -1 && a <= 1) && (b >= -1 && b <= 1)) { System.out.println("yes"); } else
System.out.println("no"); }
} }