![](https://img-blog.csdnimg.cn/20201014180756923.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Java练习题
止酒
这个作者很懒,什么都没留下…
展开
-
Java-键盘输入成绩,自定义异常类MyException用于检测输入的成绩大于100或者小于0时,抛出异常,否则就输出成绩
import java.util.Scanner;class A{ int score; public A(int score) throws Exception{ if(score<0||score>100) { throw new Exception("Error,score should be in 0-100."); } else{ this.score=score; } } void shuchu() { System.out.print.原创 2021-11-18 21:46:36 · 4833 阅读 · 0 评论 -
Java-定义一个描述三角形的类,根据输入的三边长,生成一个对象,最后输出周长、面积、边长
import java.util.Scanner;import java.lang.Math;class Triangle { private double a, b, c,meter,p,area; double getPerimeter() { meter=a+b+c; return meter; } void getArea() { p=meter/2; area=p*(p-a)*(p-b)*(p-c); area=Math.sqrt(area); Syste.原创 2021-11-18 21:42:37 · 1533 阅读 · 0 评论 -
Java-定义一个 Retangle类,有长、宽等属性,定义构造方法用来初始化类的这些属性,定义方法输出Retangle的长宽和面积。编写应用程序使用Retangle
import java.util.Scanner; class Retangle { float length,width; void jishuanarea() { float area=length*width; System.out.println("The area is:"+area); } void lenandwid() { System.out.println("The lengh is:"+length); System.out.println("The .原创 2021-11-18 21:41:48 · 2270 阅读 · 0 评论 -
Java-请编写一个方法实现如下功能: 输出任意三个整数 a,b,c中最大的一个,并打印出来
import java.util.Scanner;public class Main { public static void main(String args[]){ System.out.println("Please input the first number:"); System.out.println("Please input the second number:"); System.out.println("Please input the third number:".原创 2021-11-18 21:40:16 · 916 阅读 · 0 评论 -
Java-给出一百分制成绩,要求输出成绩等级’A’,’B’,’C’,’D’,’E’。90 分以 上 为’A’,80~89 分为’B’,70~79 分为’C’,60~69 分为’D’,60 分以下为’E
import java.util.Scanner;public class Main { public static void main(String args[]){ System.out.printf("Please input a score:\n"); Scanner in = new Scanner(System.in); int a= in.nextInt(); char x; if (a>=90) x='A'; else if (a>=80&&.原创 2021-11-18 21:39:16 · 2515 阅读 · 0 评论 -
Java-从键盘输入三个整数,分别存入x.y.z三个整型变量中,计算并输出三个数的和以及平均值
import java.util.Scanner;public class Main{ public static void main(String args[]){ Scanner in = new Scanner(System.in); int a = in.nextInt(); int b = in.nextInt(); int c = in.nextInt(); float sum; double aver; sum=a+b+c; aver=sum/3.0; .原创 2021-11-18 21:37:06 · 7286 阅读 · 0 评论