用java对100个随机生成长宽的矩形依照面积大小进行排序

用java对100个随机生成长宽的矩形依照面积大小进行排序,第1张

public static void main(String[] args) {

int[] m = new int[100];

for (int i = 0; i < 100; i++) {

//长

int h = (int)(Mathrandom()100+1);

//宽

int w = (int)(Mathrandom()100+1);

m[i] = h  w;

}

//进行排序

Arrayssort(m);

for(int i: m){

Systemoutprintln(i);

}

}

首先获取长宽画出所有表格,依次给每一个方格一个ID,并且添加ONCLICK事件。

按照ID放入库方。

使用AJAX动态查询数据显示下边的库区。下边的库区表可以给个DISPLAY:NONE,单击了让他显示就好

package comtmgpstest;

import javautilScanner;

public class test {

public static void main(String[] args) {

Scanner input = new Scanner(Systemin);

Systemoutprintln("请输入长方体的长");

int a=inputnextInt();

Systemoutprintln("请输入长方体的宽");

int b=inputnextInt();

Systemoutprintln("请输入长方体的高");

int c=inputnextInt();

Systemoutprintln("长方体的体积为:"+abc);

}

}

长宽高都可以自己输入

BufferedImage image=new BufferedImage(80, 20, BufferedImageTYPE_INT_RGB);

Graphics g=imagegetGraphics();

Random r=new Random();

gsetColor(new Color(rnextInt(255),rnextInt(255), rnextInt(255)));

gfillRect(0, 0, 80, 20);

gsetColor(ColorBLACK);

String num=rnextInt(99999)+"";

ActionContextgetContext()getSession()put("num", num);

gdrawString(num, 5, 15);

ByteArrayOutputStream os=new ByteArrayOutputStream();//创建内存输出流

JPEGImageEncoder encoder=JPEGCodeccreateJPEGEncoder(os); //将输出流用于 创建JPEG编码对象

try {

encoderencode(image);//编码

inputStream=new ByteArrayInputStream(ostoByteArray());//将输出流转换为输入流,以便存入内存,方便struts2xml中参数以getInputStream()获取

} catch (ImageFormatException e) {

// TODO Auto-generated catch block

eprintStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

eprintStackTrace();

}

这是最近我们能上课讲的生成验证码的方法,包括创建

import javautilScanner;

/

BOX

@author Administrator

/

class Box{

/

/

private int longer;

/

/

private int wider;

/

/

private int high;

/

计算体积

@param longer

@param wider

@param high

@return

/

public int getVolume(int longer, int wider, int high){

return longer wider high;

}

public int getLonger() {

return longer;

}

public void setLonger(int longer) {

thislonger = longer;

}

public int getWider() {

return wider;

}

public void setWider(int wider) {

thiswider = wider;

}

public int getHigh() {

return high;

}

public void setHigh(int high) {

thishigh = high;

}

}

public class Test{

public static void main(String[] args) {

Box box = new Box();

// 从控制输入参数

Scanner sc = new Scanner(Systemin);

Systemoutprintln("请输入BOX的长:");

boxsetLonger(scnextInt());

Systemoutprintln("请输入BOX的宽:");

boxsetWider(scnextInt());

Systemoutprintln("请输入BOX的高:");

boxsetHigh(scnextInt());

Systemoutprintln("请输入BOX的长:" + boxgetLonger() + ",宽:" + boxgetWider() + ",高:" + boxgetHigh());

Systemoutprintln("计算BOX的体积为长宽高:" + boxgetVolume(boxgetLonger(), boxgetWider(), boxgetHigh()));

}

}

以上是我的个人理解,希望能够帮助你。

这种最好是写一个抽象类,然后实例化。

public class Test {

public static void main(String[] args) {

Shape circle = new Circle(2);

Systemoutprintln("半径为2的圆的面积为:" + circlearea());

Shape triple = new Triple(3, 4, 5);

Systemoutprintln("三边长为3, 4, 5的三角形面积为: "+ triplearea());

Shape rectangle = new Rectangle(5, 6);

Systemoutprintln("长宽为5 和6的矩形面积为: "+ rectanglearea());

}

}

abstract class Shape{

public abstract double area();

}

class Circle extends Shape{//圆

private double r;

public Circle(double r){

thisr = r;

}

public double area() {

return MathPI Mathpow(r, 2);//圆周率半径的平方

}

}

class Triple extends Shape{//三角形

private double a;

private double b;

private double c;

public Triple(double a, double b, double c){

thisa = a;

thisb = b;

thisc = c;

}

//海伦公式S= √[p(p - a)(p - b)(p - c), p = (a+b+c/2)

public double area() {

double p = (a + b + c) / 2;

return Mathsqrt(p (p-a) (p - b) (p-c));

}

}

class Rectangle extends Shape{//矩形

private double width;//宽

private double height;//长

public Rectangle(double width, double height){

thiswidth = width;

thisheight = height;

}

public double area() {

return width thisheight;

}

}

---------------------测试结果

半径为2的圆的面积为:12566370614359172

三边长为3, 4, 5的三角形面积为: 60

长宽为5 和6的矩形面积为: 300

以上就是关于用java对100个随机生成长宽的矩形依照面积大小进行排序全部的内容,包括:用java对100个随机生成长宽的矩形依照面积大小进行排序、java web端用表里的长、高字段画一个表格,然后取另一张表的数据放入小方格中、用JAVA程序编写一道:求一长方体的体积,(长3宽4高5)等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

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

原文地址: https://outofmemory.cn/web/10148617.html

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

发表评论

登录后才能评论

评论列表(0条)

保存