鲸落668 2022-05-17 19:35 采纳率: 0%
浏览 75

java 关于圆柱的比较

求解如何将多个圆柱,根据他们的半径和高进行排序呢? 求指点……

  • 写回答

3条回答 默认 最新

  • 程序喵正在路上 后端领域新星创作者 2022-05-17 19:53
    关注

    你可以参考一下,希望采纳支持一下
    1、Student类

    public class Student implements Comparable{
        //成员变量name
        private String name;
    
        //构造方法
        public Student(String name){
            this.name = name;
        }
    
        //get方法
        public String getName(){
            return this.name;
        }
    
        @Override
        public int compareTo(Object O) {
            Student s = (Student) O;
            return this.name.compareTo(s.name);
        }
    }
    

    StudentTest类

    import java.util.Arrays;
    
    public class StudentTest {
        public static void main(String[] args){
            Student[] StudentArray = {
                    new Student("tom"),
                    new Student("jerry"),
                    new Student("daniel"),
                    new Student("liang"),
                    new Student("liu"),
                    new Student("lin")
            };
            System.out.println("排序前:");
            for(int i=0;i<StudentArray.length;i++){
                if(i != StudentArray.length - 1)
                    System.out.print(StudentArray[i].getName() + ",");
                else
                    System.out.print(StudentArray[i].getName());
            }
    
            Arrays.sort(StudentArray);
    
            System.out.println("\n排序后:");
            for(int i=0;i<StudentArray.length;i++){
                if(i != StudentArray.length - 1)
                    System.out.print(StudentArray[i].getName() + ",");
                else
                    System.out.print(StudentArray[i].getName());
            }
        }
    }
    

    程序执行结果如下:

    img

    2.文字闪烁
    FlashingText类

    import javax.swing.*;
    
    public class FlashingText extends JFrame implements Runnable {
        private JLabel jlblText;
    
        public FlashingText()  {
            jlblText = new JLabel("Welcome",JLabel.CENTER);
            add(jlblText);
            new Thread(this).start();
    
            this.setDefaultCloseOperation(EXIT_ON_CLOSE);
            this.setBounds(400,300,300,300);
            this.setVisible(true);
        }
    
        @Override
        public void run() {
            try{
                while (true){
                    if (jlblText.getText()==null)
                        jlblText.setText("Welcome");
                    else
                        jlblText.setText(null);
    
                    Thread.sleep(200);
                }
            }catch (InterruptedException ex){
    
            }
        }
    
        public static void main(String[] args) {
            FlashingText ft = new FlashingText();
        }
    }
    

    程序执行结果如下:

    img

    评论 编辑记录
    1人已打赏

报告相同问题?

问题事件

  • 创建了问题 5月17日

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器