用java编写程序: 1、 外部输入3个浮点数据,判断是否构成一个三角形;
用java编写程序:1、外部输入3个浮点数据,判断是否构成一个三角形;若能构建,计算三角形周长和面积;若不能,修改其中的一个值,让三个值可以构建成为一个三角形,并输出修改...
用java编写程序:
1、 外部输入3个浮点数据,判断是否构成一个三角形;若能构建,计算三角形周长和面积;若不能,修改其中的一个值,让三个值可以构建成为一个三角形,并输出修改后的新的三角形的3条边。
2、给出三个整数3,5,6;若要用这三个值构成三角形,可以修改任意一条边;比较任意固定2条边的长度,通过修改第三个值让三个数满足构成三角形。求出构成三角形面积最小的修改方案,并输出这个三角形的3条边,周长,面积。 展开
1、 外部输入3个浮点数据,判断是否构成一个三角形;若能构建,计算三角形周长和面积;若不能,修改其中的一个值,让三个值可以构建成为一个三角形,并输出修改后的新的三角形的3条边。
2、给出三个整数3,5,6;若要用这三个值构成三角形,可以修改任意一条边;比较任意固定2条边的长度,通过修改第三个值让三个数满足构成三角形。求出构成三角形面积最小的修改方案,并输出这个三角形的3条边,周长,面积。 展开
1个回答
展开全部
1.
import java.util.Scanner;
public class test{
private static double numA,numB,numC;
private static void input(){
if ((numA+numB>numC)&&(numA+numC>numB)&&(numB+numC>numA)&&numA>0&&numB>0&&numC>0) {
}else{
System.out.println("这三条边不构成三角形,请修改边!");
showMenu();
input();
}
}
private static void showMenu(){
System.out.println("1.第一条边");
System.out.println("2.第二条边");
System.out.println("3.第三条边");
System.out.print("请选择你要修改的边:");
int choose = new Scanner(System.in).nextInt();
switch (choose) {
case 1:
System.out.print("请输入第一条边:");
numA = new Scanner(System.in).nextDouble();
break;
case 2:
System.out.print("请输入第二条边:");
numB = new Scanner(System.in).nextDouble();
break;
case 3:
System.out.print("请输入第三条边:");
numC = new Scanner(System.in).nextDouble();
break;
default:
System.out.println("输入错误,请重新输入!");
System.out.println("");
showMenu();
break;
}
if ((numA+numB>numC)&&(numA+numC>numB)&&(numB+numC>numA)&&numA>0&&numB>0&&numC>0) {
System.out.println("");
System.out.println("修改后的三条边如下:");
System.out.println("第一条边:"+numA);
System.out.println("第二条边:"+numB);
System.out.println("第三条边:"+numC);
input();
}else{
System.out.println("这三条边不构成三角形!");
System.out.println("");
showMenu();
}
}
public static void main(String[] args) {
System.out.print("请输入三角形的第一条边:");
numA = new Scanner(System.in).nextDouble();
System.out.print("请输入三角形的第二条边:");
numB = new Scanner(System.in).nextDouble();
System.out.print("请输入三角形的第三条边:");
numC = new Scanner(System.in).nextDouble();
input();
double squre,ciclye,p;
if ((numA+numB>numC)&&(numA+numC>numB)&&(numB+numC>numA)&&numA>0&&numB>0&&numC>0) {
p = (numA+numB+numC)/2.0;
squre=Math.sqrt(p*(p-numA)*(p-numB)*(p-numC));
ciclye=numA+numB+numC;
System.out.println("");
System.out.println("这三条边可以构成三角形!");
System.out.println("这个三角形周长是:"+ciclye+",面积是:"+squre);
}
}
}
2.
import java.util.Scanner;
public class test{
private static double numA,numB,numC,num[]=new double[3],numTemp[]=new double[3],temp;
private static int bFlage;
private static void input(){
num[0]=numA;
num[1]=numB;
num[2]=numC;
for (int i = 0; i < numTemp.length; i++) {
numTemp[i]=num[i];
}
if ((numA+numB>numC)&&(numA+numC>numB)&&(numB+numC>numA)&&numA>0&&numB>0&&numC>0) {
}else{
System.out.println("这三条边不构成三角形,请修改边!");
for (int i = 0; i < numTemp.length; i++) {
for (int j = 0; j < numTemp.length-i-1; j++) {
if (numTemp[j]<numTemp[j+1]) {
temp=numTemp[j];
numTemp[j]=numTemp[j+1];
numTemp[j+1]=temp;
}
}
}
for (int i = 0; i < num.length; i++) {
if (numTemp[0]==num[i]) {
bFlage=i;
break;
}
}
System.out.print("要使三角形面积最小时,必须修改:");
switch (bFlage) {
case 0:
System.out.println("第一条边!");
break;
case 1:
System.out.println("第二条边!");
break;
case 2:
System.out.println("第三条边!");
break;
}
showMenu();
input();
}
}
private static void showMenu(){
System.out.println("1.第一条边");
System.out.println("2.第二条边");
System.out.println("3.第三条边");
System.out.print("请选择你要修改的边:");
int choose = new Scanner(System.in).nextInt();
switch (choose) {
case 1:
System.out.print("请输入第一条边:");
numA = new Scanner(System.in).nextDouble();
num[0]=numA;
break;
case 2:
System.out.print("请输入第二条边:");
numB = new Scanner(System.in).nextDouble();
num[1]=numB;
break;
case 3:
System.out.print("请输入第三条边:");
numC = new Scanner(System.in).nextDouble();
num[2]=numC;
break;
default:
System.out.println("输入错误,请重新输入!");
System.out.println("");
showMenu();
break;
}
if ((numA+numB>numC)&&(numA+numC>numB)&&(numB+numC>numA)&&numA>0&&numB>0&&numC>0) {
System.out.println("");
System.out.println("修改后的三条边如下:");
System.out.println("第一条边:"+numA);
System.out.println("第二条边:"+numB);
System.out.println("第三条边:"+numC);
input();
}else{
System.out.println("这三条边不构成三角形!");
System.out.print("要使三角形面积最小时,必须修改:");
switch (bFlage) {
case 0:
System.out.println("第一条边!");
break;
case 1:
System.out.println("第二条边!");
break;
case 2:
System.out.println("第三条边!");
break;
}
System.out.println("");
showMenu();
}
}
public static void main(String[] args) {
System.out.print("请输入三角形的第一条边:");
numA = new Scanner(System.in).nextDouble();
System.out.print("请输入三角形的第二条边:");
numB = new Scanner(System.in).nextDouble();
System.out.print("请输入三角形的第三条边:");
numC = new Scanner(System.in).nextDouble();
input();
double squre,ciclye,p;
if ((numA+numB>numC)&&(numA+numC>numB)&&(numB+numC>numA)&&numA>0&&numB>0&&numC>0) {
p = (numA+numB+numC)/2.0;
squre=Math.sqrt(p*(p-numA)*(p-numB)*(p-numC));
ciclye=numA+numB+numC;
System.out.println("");
System.out.println("这三条边可以构成三角形!");
System.out.println("这个三角形周长是:"+ciclye+",面积是:"+squre);
}
}
}
import java.util.Scanner;
public class test{
private static double numA,numB,numC;
private static void input(){
if ((numA+numB>numC)&&(numA+numC>numB)&&(numB+numC>numA)&&numA>0&&numB>0&&numC>0) {
}else{
System.out.println("这三条边不构成三角形,请修改边!");
showMenu();
input();
}
}
private static void showMenu(){
System.out.println("1.第一条边");
System.out.println("2.第二条边");
System.out.println("3.第三条边");
System.out.print("请选择你要修改的边:");
int choose = new Scanner(System.in).nextInt();
switch (choose) {
case 1:
System.out.print("请输入第一条边:");
numA = new Scanner(System.in).nextDouble();
break;
case 2:
System.out.print("请输入第二条边:");
numB = new Scanner(System.in).nextDouble();
break;
case 3:
System.out.print("请输入第三条边:");
numC = new Scanner(System.in).nextDouble();
break;
default:
System.out.println("输入错误,请重新输入!");
System.out.println("");
showMenu();
break;
}
if ((numA+numB>numC)&&(numA+numC>numB)&&(numB+numC>numA)&&numA>0&&numB>0&&numC>0) {
System.out.println("");
System.out.println("修改后的三条边如下:");
System.out.println("第一条边:"+numA);
System.out.println("第二条边:"+numB);
System.out.println("第三条边:"+numC);
input();
}else{
System.out.println("这三条边不构成三角形!");
System.out.println("");
showMenu();
}
}
public static void main(String[] args) {
System.out.print("请输入三角形的第一条边:");
numA = new Scanner(System.in).nextDouble();
System.out.print("请输入三角形的第二条边:");
numB = new Scanner(System.in).nextDouble();
System.out.print("请输入三角形的第三条边:");
numC = new Scanner(System.in).nextDouble();
input();
double squre,ciclye,p;
if ((numA+numB>numC)&&(numA+numC>numB)&&(numB+numC>numA)&&numA>0&&numB>0&&numC>0) {
p = (numA+numB+numC)/2.0;
squre=Math.sqrt(p*(p-numA)*(p-numB)*(p-numC));
ciclye=numA+numB+numC;
System.out.println("");
System.out.println("这三条边可以构成三角形!");
System.out.println("这个三角形周长是:"+ciclye+",面积是:"+squre);
}
}
}
2.
import java.util.Scanner;
public class test{
private static double numA,numB,numC,num[]=new double[3],numTemp[]=new double[3],temp;
private static int bFlage;
private static void input(){
num[0]=numA;
num[1]=numB;
num[2]=numC;
for (int i = 0; i < numTemp.length; i++) {
numTemp[i]=num[i];
}
if ((numA+numB>numC)&&(numA+numC>numB)&&(numB+numC>numA)&&numA>0&&numB>0&&numC>0) {
}else{
System.out.println("这三条边不构成三角形,请修改边!");
for (int i = 0; i < numTemp.length; i++) {
for (int j = 0; j < numTemp.length-i-1; j++) {
if (numTemp[j]<numTemp[j+1]) {
temp=numTemp[j];
numTemp[j]=numTemp[j+1];
numTemp[j+1]=temp;
}
}
}
for (int i = 0; i < num.length; i++) {
if (numTemp[0]==num[i]) {
bFlage=i;
break;
}
}
System.out.print("要使三角形面积最小时,必须修改:");
switch (bFlage) {
case 0:
System.out.println("第一条边!");
break;
case 1:
System.out.println("第二条边!");
break;
case 2:
System.out.println("第三条边!");
break;
}
showMenu();
input();
}
}
private static void showMenu(){
System.out.println("1.第一条边");
System.out.println("2.第二条边");
System.out.println("3.第三条边");
System.out.print("请选择你要修改的边:");
int choose = new Scanner(System.in).nextInt();
switch (choose) {
case 1:
System.out.print("请输入第一条边:");
numA = new Scanner(System.in).nextDouble();
num[0]=numA;
break;
case 2:
System.out.print("请输入第二条边:");
numB = new Scanner(System.in).nextDouble();
num[1]=numB;
break;
case 3:
System.out.print("请输入第三条边:");
numC = new Scanner(System.in).nextDouble();
num[2]=numC;
break;
default:
System.out.println("输入错误,请重新输入!");
System.out.println("");
showMenu();
break;
}
if ((numA+numB>numC)&&(numA+numC>numB)&&(numB+numC>numA)&&numA>0&&numB>0&&numC>0) {
System.out.println("");
System.out.println("修改后的三条边如下:");
System.out.println("第一条边:"+numA);
System.out.println("第二条边:"+numB);
System.out.println("第三条边:"+numC);
input();
}else{
System.out.println("这三条边不构成三角形!");
System.out.print("要使三角形面积最小时,必须修改:");
switch (bFlage) {
case 0:
System.out.println("第一条边!");
break;
case 1:
System.out.println("第二条边!");
break;
case 2:
System.out.println("第三条边!");
break;
}
System.out.println("");
showMenu();
}
}
public static void main(String[] args) {
System.out.print("请输入三角形的第一条边:");
numA = new Scanner(System.in).nextDouble();
System.out.print("请输入三角形的第二条边:");
numB = new Scanner(System.in).nextDouble();
System.out.print("请输入三角形的第三条边:");
numC = new Scanner(System.in).nextDouble();
input();
double squre,ciclye,p;
if ((numA+numB>numC)&&(numA+numC>numB)&&(numB+numC>numA)&&numA>0&&numB>0&&numC>0) {
p = (numA+numB+numC)/2.0;
squre=Math.sqrt(p*(p-numA)*(p-numB)*(p-numC));
ciclye=numA+numB+numC;
System.out.println("");
System.out.println("这三条边可以构成三角形!");
System.out.println("这个三角形周长是:"+ciclye+",面积是:"+squre);
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |