几道JAVA题目,求好心人给下答案,感激不尽

几道JAVA题目,求好心人给下答案,感激不尽,第1张

1、public static void main(String[] args)

2、public finall static

3、3

4、抽象类

5、implements

6、类:一个包含属性、方法,使用class关键字定义

   对象:创建对象必须使用new关键字,对象其实在内存中存储的是类的引用地址。

7、try是可能发生异常的内容;

   catch是发生异常后要处理的代码;

   finally是始终执行的,比如关闭资源等。

8、

public class Demo {

//小明今年12岁,他母亲比他大20岁。编程计算多少年后他母亲的年龄是小明的2倍。

public static void main(String[] args) {

System.out.println(getYeah())

}

public static int getYeah(){

int xmAge = 12,mqAge = 20,yeah = 0

while(true){

if(mqAge / 2 == xmAge){

return yeah

}

mqAge++

yeah++

}

}

}

9、

public class Demo {

public static void main(String[] args) {

new Thread(new Piao()).start()

new Thread(new Piao()).start()

new Thread(new Piao()).start()

new Thread(new Piao()).start()

}

}

class Piao implements Runnable{

private static int piao = 1

public  void run(){

while(true){

synchronized(Piao.class){

if(piao > 100){

System.exit(0)

}

System.out.println(Thread.currentThread().getName()+"出票:" + piao + "号")

piao++

}

}

}

}

public class Point {

int x

int y

public Point() {

}

public Point(int x, int y) {

this.x = x

this.y = y

}

public Point(int x) {

this.x = x

this.y = x

}

public double distance() {//求当前点到原点的距离

return Math.sqrt((x * x + y * y))

}

public double distance(int x1, int y1) {//求当前点到(x1,y1)的距离

return Math.sqrt((x-x1)*(x-x1) + (y-y1) * (y-y1))

}

public double distance(Point other){

int x2 = other.x

int y2 = other.y

return Math.sqrt((x-x2)*(x-x2) + (y-y2) * (y-y2))

}

}

注释就不写了,将就着看吧

awt/swing的题目就算了,懒得写,很少用

1、声明一个类Person,成员变量有姓名、出生年月、性别。有成员方法以显示姓名、年龄和性别。

import java.text.SimpleDateFormat

import java.util.Date

class Person {

public Person(String name, Date birthday, boolean isMale) {

super()

this.name = name

this.birthday = birthday

this.isMale = isMale

}

private String name

private Date birthday

private boolean isMale

public void showName() {

System.out.println("姓名:" + name)

}

public void showBirthday() {

System.out.println("出生年月日:"

+ new SimpleDateFormat("yyyy年MM月dd日").format(birthday))

}

public void showSex() {

System.out.print("性别:")

if (isMale){

System.out.println("男")

} else {

System.out.println("女")

}

}

}

2、声明一个接口,将一个人的出生年份转换成年龄

public interface DateUtil {

public int DateToAge()

}

3、在类Shapearea中声明三个同名方法求圆、矩形和三角形的面积(三个方法有不同的参数)。

public class Shapearea {

static final double PI=3.1415926

public static double getArea(double r){

return r*r*PI

}

public static double getArea(double x,double y){

return x*y

}

public static double getArea(double a,double b,double c){

double l=a+b+c

return Math.sqrt(l*(l-c)*(l-b)*(l-a))

}

}

4、已知某一角度的值,求它的正弦值。

Math.sin(a)

5、由键盘输入两个字符串“10”和“20”,将他们转换成整数,然后计算并输出这两个数的和。

Scanner sc=new Scanner(System.in)

String str1=sc.next()

String str2=sc.next()

Integer int1=new Integer(str1)

Integer int2=new Integer(str2)

System.out.println("结果是:"+int1+int2)

6绘图

7、绘制一圆角矩形、实心普通矩形,分别使用不同的颜色。

8、绘制一多边形(至少4个顶点)和一空心弧线(长度和角度自定)。颜色自定。

9、绘制一折线(至少六个顶点)和一正方形。颜色自定。

10、创建一个String类的对象Str1和Str2,判断Str2是否str1的子串。如果是,输出str1中在子串str2后的字符串。

Scanner sc=new Scanner(System.in)

String str1=sc.next()

String str2=sc.next()

if (str1.contains(str2)) {

System.out.println(str1.split(str2, 2)[1])

}

11、声明一个矩形类Rectangle,其中有多个构造方法。用不同的构造方法创建对象,并输出矩形的周长和面积。

12、完成一小应用程序,实现用CardLayout布局摆放三个按钮(每张卡片上一个按钮,点击按钮换卡片。)


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/11860922.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-19
下一篇2023-05-19

发表评论

登录后才能评论

评论列表(0条)

    保存