一些简单的 Java 题 急 高分求高手解答
发布网友
发布时间:2023-12-02 08:16
我来回答
共5个回答
热心网友
时间:2024-06-01 18:19
public class Test {
public static void main(String[] args) {
System.out.println(xuefei(10));
san();
}
/**
*
*/
private static void san() {
double bian[] = new double[3];
for (int i = 1; i < 4; i++) {
// MyInput.readDouble(bian[i]);
}
bian[0] = 12.12;
bian[1] = 12.12;
bian[2] = 12.12;
if (bian[0] + bian[1] > bian[2] && bian[0] + bian[2] > bian[1] && bian[1] + bian[2] > bian[0]) {
System.out.println("能组成三角形");
} else {
System.out.println("不能组成三角形");
}
}
private static double xuefei(int n) {
double xue = 10000;
for (int i = 1; i <= 10; i++) {
xue = xue * (1 + 0.05);
}
return xue;
}
}
热心网友
时间:2024-06-01 18:19
A2: double cout=10000;
int num=10;
int sum=0;
for(int i=1;i<=num;i++)
{
sum+=cout*1.05;
}
热心网友
时间:2024-06-01 18:20
多好的题目啊
自己摸索
先把算法设计好
if(a+b>c and a+c>b and b+c>a and abs(a-b)<c and abs(a-c)<b
and abs(b-c)<a)
这个多啰嗦
热心网友
时间:2024-06-01 18:21
//看在高分的份上,我也来凑个热闹
//: A1.java
import java.io.*;
//A1类
public class A1 {
private double a,b,c;
//用三边的数值来构造一个三角形
A1(double a,double b,double c){
this.a=a;
this.b=b;
this.c=c;
}
//判断能否组成三角形
public boolean canBeATriangle(){
return //任意两边之和大于第三边而且每个边的值要大于0就是三角形
a+b>c && b+c>a && a+c>b
&&
a>0 && b>0 && c>0;
}
public static void main(String[] args) throws Exception{
//开始测试A1
String usage = "请输入三角形的三边的长度,每个数值用空格分隔开(回车结束):";
System.out.println(usage);
double a=0,b=0,c=0;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String tmp = null;
do{
try{
tmp = br.readLine();
String[] ns = tmp.trim().split(" +");
a=Double.parseDouble(ns[0]);
b=Double.parseDouble(ns[1]);
c=Double.parseDouble(ns[2]);
System.out.println("你输入的三角形的三边长度是: "+a+","+b+","+c);
break;
}catch(Exception e){
System.out.println("你的输入不符合输入条件");
System.out.println(usage);
}
}while(true);
A1 a1 = new A1(a,b,c);
boolean isTriangle = a1.canBeATriangle();
if(isTriangle){
System.out.println("三边长度为: "+a+","+b+","+c+" 能组成一个三角形.");
}
else{
System.out.println("三边长度为:"+a+","+b+","+c+" 不能组成一个三角形.");
}
//测试A1结束
Thread.sleep(1000);
//开始测试A2
double initv = 10000;
double inc = 5d/100;
int years = 10;
System.out.println("初始学费: "+initv+", 年增长率: "+inc+", 那么 "+years+" 内的学费情况如下:");
A2 a2 = new A2(initv,inc);
//打印下一个10年的学费情况
for(int i=1; i<=years; i++){
double tmpv = a2.getValueAfterYears(i);
//打印第N年的学费
System.out.print(i+ " 年后的学费是: "+tmpv+" ");
//打印N年后的总学费
System.out.println("就读"+i+" 年的总学费是: "+a2.getTotalAfterYears(i));
}
//测试A2结束
}
}
//A2类
class A2{
private double value;//原始值
private double inc;//增长率
//用初始学费和年增长率来构造对象
public A2(double v,double i){
this.value=v;
this.inc=i;
}
//获取N年后的学费
public double getValueAfterYears(int years){
double tmp = value;
for(int i=0; i<years; i++){
tmp+=tmp*inc;
}
return tmp;
}
//获取N年后的总学费
public double getTotalAfterYears(int years){
double t = value;
while(--years>0)
t+=this.getValueAfterYears(years);
return t;
}
}
热心网友
时间:2024-06-01 18:21
/**
* 使用下面方法前请确认你的JDK是1.5或以上版本
* */
public class MainScanner {
public static double a = 0;
public static double b = 0;
public static double c = 0;
/**
* 判断是不是可以组成一个三角形
* */
public static boolean util(List<Double> list) {
if (list.size() == 3) {
a = list.get(0);
b = list.get(1);
c = list.get(2);
if (a + b > c && java.lang.Math.abs(a - b) < c) {
System.out.println("OK,可以组成一个三角形");
} else {
System.out.println("不可以组成一个三角形");
}
return true;
} else {
return false;
}
}
// 第二个问题
// public static void expense(){
// double n=10000;
// for(int i = 1; i <= 10; i++) {
// n = n * (1 + 0.05);
// System.out.println(n);
// }
// }
public static void main(String args[]) throws Exception {
String validate = "^\\d+(\\.\\d+)?$";
List<Double> list = new ArrayList<Double>();
// 第二个问题
// expense();
while (true) {
System.out.println("Please Input Int:");
Scanner cin = new Scanner(System.in);
String str = cin.nextLine();
if (!str.matches(validate)) {
System.out.println("输入错误 请重新输入");
continue;
}
list.add(Double.parseDouble(str));
if (util(list)) {
list.clear();
}
}
}
}