我对java和api上的方法有问题,能给我一些建议吗?

0qx6xfy6  于 2021-07-07  发布在  Java
关注(0)|答案(0)|浏览(142)

我的任务是拆分我的程序,它允许用户输入一个数字数组,在1到10之间的奇数之后检查奇数是否是数组中5个数字的一个因子。我在理解如何拆分这些方法以及如何命名它们时遇到了问题。注意:我不允许使用静态方法。有人能帮帮我吗?程序如下:

import javax.swing.*;  
import java.awt.event.*;    
import java.util.Scanner;
public class SchoolWorkProg3 {  
    public void CheckBoxExample(){    
        JFrame f= new JFrame("Are you a robot?");    
        final JLabel label = new JLabel();            
        label.setHorizontalAlignment(JLabel.CENTER);    
        label.setSize(400,100);    
        JCheckBox checkbox1 = new JCheckBox("Yes");    
        checkbox1.setBounds(150,100, 50,50);    
        JCheckBox checkbox2 = new JCheckBox("No");    
        checkbox2.setBounds(150,150, 50,50);    
        f.add(checkbox1); f.add(checkbox2); f.add(label);    
        checkbox1.addItemListener(new ItemListener() {    
                public void itemStateChanged(ItemEvent e) {                 
                    label.setText("Yes Checkbox: "     
                        + (e.getStateChange()==1?"checked":"unchecked"));    
                }    
            });    
        checkbox2.addItemListener(new ItemListener() {    
                public void itemStateChanged(ItemEvent e) {                 
                    label.setText("No Checkbox: "     
                        + (e.getStateChange()==1?"checked":"unchecked"));    
                }    
            });    
        f.setSize(400,400);    
        f.setLayout(null);    
        f.setVisible(true);    
    }    

    public void output ()    
    {    
        new CheckBoxExample();    
    }    

    public void factor () { 
        Scanner s = new Scanner(System.in);
        int array[] = new int[10];
        System.out.println ("Please enter 10 random numbers");
        for (int i = 0; i < 10; i++) {
            array[i] = s.nextInt();
        }

        System.out.println ("Please enter an odd number between 1 and 10");
        int num = s.nextInt ();
        if (num < 0 & num > 10){
            System.out.println ("Your number is outside of the range, try again");
        } else if (num % 2 == 0){
            System.out.println ("\nYour number is even, enter an odd one");
        }

        boolean result = true;
        for (int i = 0; i < 0 ; i++){
            if (num % array[i] == 0) {

            } else {
                result = false;
            }

            if(result){
                System.out.println("Number" + num + "is not a factor of" + array[i] );
            }else{
                System.out.println("Number" + num + "is a factor of" + array[i]);
            }
        }
    }
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题