JAVA 从键盘输入三个正数,判断这三个数能否构成三角形的三条边长;
从键盘输入三个正数,判断这三个数能否构成三角形的三条边长;编程题3:编写程序,根据从键盘输入的学生成绩,输出相应的等级;(用switch-case)90-100优秀80-...
从键盘输入三个正数,判断这三个数能否构成三角形的三条边长;
编程题3:编写程序,根据从键盘输入的学生成绩,输出相应的等级;(用switch-case)
90-100 优秀
80-89 良好
70-79 中等
60-69 及格
0-59 不及格 展开
编程题3:编写程序,根据从键盘输入的学生成绩,输出相应的等级;(用switch-case)
90-100 优秀
80-89 良好
70-79 中等
60-69 及格
0-59 不及格 展开
若以下回答无法解决问题,邀请你更新回答
2个回答
展开全部
三角形判断:
package pack_triangle;
import java.io.*;
public class Triangle {
public static void main(String[] args)throws IOException {
double a,b,c;
BufferedReader in1=new BufferedReader(new InputStreamReader(System.in));
BufferedReader in2=new BufferedReader(new InputStreamReader(System.in));
BufferedReader in3=new BufferedReader(new InputStreamReader(System.in));
System.out.print("请输入边长a: ");
String line1=in1.readLine();
a=Double.parseDouble(line1);
System.out.print("请输入边长b: ");
String line2=in2.readLine();
b=Double.parseDouble(line2);
System.out.print("请输入边长c: ");
String line3=in3.readLine();
c=Double.parseDouble(line3);
if(a+b>c && a+c>b && b+c>a)
System.out.println("a、b、c可以构成三角形!");
else
System.out.println("a、b、c不可以构成三角形!");
}
}
成绩等级判断:
package pack_grade;
import java.io.*;
public class Grade {
public static void main(String[] args)throws IOException {
double x;
int a;
BufferedReader in1=new BufferedReader(new InputStreamReader(System.in));
System.out.print("请输入成绩X:");
String line1=in1.readLine();
x=Double.parseDouble(line1);
a=(x>=90 && x<=100 ? 1:0)
+(x>=80 && x<90 ? 2:0)
+(x>=70 && x<80 ? 3:0)
+(x>=60 && x<70 ? 4:0)
+(x<60 ? 5:0);
switch(a){
case 1:
System.out.println("优秀");
break;
case 2:
System.out.println("良好");
break;
case 3:
System.out.println("中等");
break;
case 4:
System.out.println("及格");
break;
case 5:
System.out.println("不及格");
break;
default:
break;
}
}
}
成绩等级判断这题我更改了一下,如当你输入89.5 这样的分数时也能判断相应的等级。
package pack_triangle;
import java.io.*;
public class Triangle {
public static void main(String[] args)throws IOException {
double a,b,c;
BufferedReader in1=new BufferedReader(new InputStreamReader(System.in));
BufferedReader in2=new BufferedReader(new InputStreamReader(System.in));
BufferedReader in3=new BufferedReader(new InputStreamReader(System.in));
System.out.print("请输入边长a: ");
String line1=in1.readLine();
a=Double.parseDouble(line1);
System.out.print("请输入边长b: ");
String line2=in2.readLine();
b=Double.parseDouble(line2);
System.out.print("请输入边长c: ");
String line3=in3.readLine();
c=Double.parseDouble(line3);
if(a+b>c && a+c>b && b+c>a)
System.out.println("a、b、c可以构成三角形!");
else
System.out.println("a、b、c不可以构成三角形!");
}
}
成绩等级判断:
package pack_grade;
import java.io.*;
public class Grade {
public static void main(String[] args)throws IOException {
double x;
int a;
BufferedReader in1=new BufferedReader(new InputStreamReader(System.in));
System.out.print("请输入成绩X:");
String line1=in1.readLine();
x=Double.parseDouble(line1);
a=(x>=90 && x<=100 ? 1:0)
+(x>=80 && x<90 ? 2:0)
+(x>=70 && x<80 ? 3:0)
+(x>=60 && x<70 ? 4:0)
+(x<60 ? 5:0);
switch(a){
case 1:
System.out.println("优秀");
break;
case 2:
System.out.println("良好");
break;
case 3:
System.out.println("中等");
break;
case 4:
System.out.println("及格");
break;
case 5:
System.out.println("不及格");
break;
default:
break;
}
}
}
成绩等级判断这题我更改了一下,如当你输入89.5 这样的分数时也能判断相应的等级。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
/*********************判断三角形**********************/
import java.io.*;
public class IsTria {
public boolean isTriangle(int l,int w,int h){
if(l+w>h)
return true;
else if(l+h>w)
return true;
else if(w+h>l)
return true;
else
return false;
}
public static void main(String[] args) {
IsTria it = new IsTria();
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int l=0,w=0,h=0;
System.out.println("请输入三条边的长度:");
try {
l = Integer.parseInt(in.readLine());
w = Integer.parseInt(in.readLine());
h = Integer.parseInt(in.readLine());
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(it.isTriangle(l,w,h))
System.out.println("这三条边可以构成三角形");
else
System.out.println("这三条边不能构成三角形");
}
}
/*******************************************************/
/********************判定学生成绩等级***************************/
import java.io.*;
public class DifferClass {
public static void main(String[] args) {
System.out.println("请输入学生成绩:");
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int grade = 0;
String inclass = "";
try {
grade = Integer.parseInt(in.readLine());
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
switch(grade/10){
case 10:
case 9: inclass = "优秀"; break;
case 8: inclass = "良好"; break;
case 7: inclass = "中等"; break;
case 6: inclass = "及格"; break;
default: inclass = "不及格"; break;
}
System.out.println("该成绩等级为:"+inclass);
}
}
import java.io.*;
public class IsTria {
public boolean isTriangle(int l,int w,int h){
if(l+w>h)
return true;
else if(l+h>w)
return true;
else if(w+h>l)
return true;
else
return false;
}
public static void main(String[] args) {
IsTria it = new IsTria();
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int l=0,w=0,h=0;
System.out.println("请输入三条边的长度:");
try {
l = Integer.parseInt(in.readLine());
w = Integer.parseInt(in.readLine());
h = Integer.parseInt(in.readLine());
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(it.isTriangle(l,w,h))
System.out.println("这三条边可以构成三角形");
else
System.out.println("这三条边不能构成三角形");
}
}
/*******************************************************/
/********************判定学生成绩等级***************************/
import java.io.*;
public class DifferClass {
public static void main(String[] args) {
System.out.println("请输入学生成绩:");
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int grade = 0;
String inclass = "";
try {
grade = Integer.parseInt(in.readLine());
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
switch(grade/10){
case 10:
case 9: inclass = "优秀"; break;
case 8: inclass = "良好"; break;
case 7: inclass = "中等"; break;
case 6: inclass = "及格"; break;
default: inclass = "不及格"; break;
}
System.out.println("该成绩等级为:"+inclass);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询