2.6**
代码如下
package Digits;
import java.util.Scanner;
public class Digits {
public static void main(String[] args) {
System.out.println("Enter an integer between 0 and 1000 :");
Scanner in = new Scanner(System.in);
int a = 0, b = 0, c = 0;
int num = in.nextInt();
if (num < 1000 && num >= 0) {
a = num % 10;
b = (num % 100 - a) / 10;
c = num / 100;
System.out.println(a + b + c);
} else {
System.out.println("Sorry,the integer must be between 0 and 1000.");
}
}
}
运行结果
Enter an integer between 0 and 1000 :
932
14
2.24
代码如下
package Digits;
import java.util.Scanner;
public class RunwayLength {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter v in meters/second(m/s) :");
double v = in.nextDouble();
System.out.println("Enter a in meters/second squared(m/s^2) :");
double a = in.nextDouble();
System.out.println("The minimum runway length for this airplane is "+0.5*v*v/a);
}
}
运行结果
Enter v in meters/second(m/s) :
60
Enter a in meters/second squared(m/s^2) :
3.5
The minimum runway length for this airplane is 514.2857142857143