「JAVA长程序」java 代码过长

博主:adminadmin 2022-11-25 03:08:09 62

本篇文章给大家谈谈JAVA长程序,以及java 代码过长对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

求一个,用Java编写一个求长方形的面积和周长的程序,(面向对象).

//看看我这个程序把 比较符合面向对象的思想,告诉搂住一声,尽量把一些程序写尽方法里,而不是都写在主方法中!这样不好~~~~ 希望对你有用!!

import java.util.Scanner;

public class Ex {

public static int squ(int x,int y){ //求面积的方法

int s = x* y;

return s;

}

public static double len(int x,int y){//求周长的方法

int l = (x+y)*2;

return l;

}

public static void main(String [] aa){

System.out.println("请输入宽:"); //从命令行输入宽

Scanner in = new Scanner(System.in);

int le = in.nextInt();

System.out.println("请输入高:");//从命令行输入高

Scanner in2 = new Scanner(System.in);

int hi = in2.nextInt(); //转换为int型

int mianji = squ(le,hi); //调用方法

System.out.println("面积是:" + mianji);

/*

* 求周长同理,调用周长那个方法即可

*/

}

}

这个Java程序太长, 我想通过追问的办法补充,谁愿意帮我改一下这个程序

进口程序。媒体。*;进口程序。摆动。*;Java AWT的进口。进口。*;Java AWT事件。。。*;公共课的MediaPlayer延伸JFrame实现ActionListener,itemlistener,controllerlistener {字符串标题;播放器;布尔第一= true,环=假;组件的VC,CC字符串的当前目录;= null;媒体播放器(字符串名称){超(标题);addwindowlistener(新windowadapter() { public void windowclosing(父类e){ dispose();} public void windowclosed(父类E){ if(球员!= null)的球员。();退出系统。(0);} });setupmenu();setsize(400,400);setVisible(true);} public void setupmenu() {菜单F =新的菜单(quot;文件quot;);MenuItem MI =新的菜单项(quot;打开”;);f.add(MI);心肌梗死。addactionlistener(本);F addseparator();菜单项中材=新的菜单项(quot;循环quot;,false);材。addactionlistener(本);f.add(材);F addseparator();MenuItem EE =新的菜单项(quot;退出quot;)addactionlistener;EE。(本);f.add(EE);F addseparator();菜单L =新的菜单(quot;播放列表quot;);菜单C =新的菜单(quot;播放控制quot;);菜单移动=新菜单项(quot;播放quot;);addactionlistener移动。(这);4.(移动);C addseparator();MenuItem暂停=新菜单项(quot;暂停quot;);暂停。addactionlistener(本);4.(停顿);C addseparator();MenuItem停止=新菜单项(quot;停止quot;);停止。addactionlistener(本);4.(停止);C addseparator();菜单栏的MB =新menubar();MB。添加(F);MB。添加(C);MB。添加(L);setmenubar(MB);}

编写java程序,输入一个长方体的长、宽、高,求长方体的表面积和体积,并将结果显示

1、长方体表面积公式 :S = 2(ab + bc + ac);

2、长方体体积公式     :V = abc = Sh;(这里的S表示底面积)。

实现如下:

public class Cuboid {

// 定义长方体的长、宽、高

private double length, width, height;

public Cuboid(double length, double width, double height) {

super();

this.length = length;

this.width = width;

this.height = height;

}

// 获取当前长方体的表面积

public double getSurface() {

return getSurface(length, width, height);

}

// 获取当前长方体的体积

public double getVolume() {

return getVolume(length, width, height);

}

// 计算长方体表面积的通用方法

public static double getSurface(double length, double width, double height) {

return 2 * (length * width + width * height + length * height);

}

// 计算长方体体积的通用方法

public static double getVolume(double length, double width, double height) {

return length * width * height;

}

public static void main(String[] args) {

// 1、创建长方体对象,计算当前长方体的表面积和体积

Cuboid cuboid = new Cuboid(1, 1.6, 4.8);

System.out.println(cuboid.getSurface());

System.out.println(cuboid.getVolume());

// 2、使用通用方法,计算任意长方体的表面积和体积

System.out.println(Cuboid.getSurface(1, 1.6, 4.8));

System.out.println(Cuboid.getVolume(1, 1.6, 4.8));

}

}

求编写几个Java程序

第一题:

package demo20;

class Number {

private int n1;

private int n2;

public Number(int n1, int n2) {

this.n1 = n1;

this.n2 = n2;

}

public int addition() {

return n1 + n2;

}

public int subtration() {

return n1 - n2;

}

public int multiplication() {

return n1 * n2;

}

public int division() {

return n1 / n2;

}

}

public class App2 {

public static void main(String[] args) {

Number number = new Number(6, 3);

System.out.println("6+3=" + number.addition());

System.out.println("6-3=" + number.subtration());

System.out.println("6*3=" + number.multiplication());

System.out.println("6/3=" + number.division());

}

}

第二题:

package demo20;

class Person {

private String name;

private int age;

public Person(String name, int age) {

this.name = name;

this.age = age;

}

public void display() {

System.out.println("我叫" + name + ",我今年" + age + "了。");

}

}

public class App3 {

public static void main(String[] args) {

Person person = new Person("张三", 25);

person.display();

}

}

第三题:

package demo20;

class Rectangle {

private int width;

private int height;

public Rectangle() {

this.width = 5;

this.height = 3;

}

public Rectangle(int width, int height) {

this.width = width;

this.height = height;

}

public int girth() {

return (this.width + this.height) * 2;

}

public int area() {

return this.width * this.height;

}

}

public class App4 {

public static void main(String[] args) {

Rectangle rect1 = new Rectangle(18, 12);

System.out.println("周长:" + rect1.girth() + ",面积:" + rect1.area());

Rectangle rect2 = new Rectangle();

System.out.println("周长:" + rect2.girth() + ",面积:" + rect2.area());

}

}

第四题:

package demo20.Sequre;

class Rectangle {

private int width;

private int height;

public Rectangle() {

this.width = 5;

this.height = 3;

}

public Rectangle(int width, int height) {

this.width = width;

this.height = height;

}

public int girth() {

return (this.width + this.height) * 2;

}

public int area() {

return this.width * this.height;

}

}

class Sequare extends Rectangle {

public Sequare(int width) {

super(width, width);

}

}

public class App5 {

public static void main(String[] args) {

Sequare sequre = new Sequare(20);

System.out.println("周长:" + sequre.girth() + ",面积:" + sequre.area());

}

}

java 长时间运行,程序失去反应

检查下是不是java的堆栈满了,或者 java内存溢出了。又或者是不是有其他东西阻拦了java进程或者调度。如果是一个循环且可回收过程的话,运行多久应该都是没有问题的 哦。

JAVA长程序的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java 代码过长、JAVA长程序的信息别忘了在本站进行查找喔。

The End

发布于:2022-11-25,除非注明,否则均为首码项目网原创文章,转载请注明出处。