嵌套的for循环完成后,如何使if语句运行?

时间:2019-01-13 17:17:55

标签: java

我想知道是否有一种方法可以在循环完成后运行if循环而不将其从循环中删除 这是我为com sci类要做的程序

编写一个程序,找出因子最多的1到1000之间的整数。例如60有 12个因子:1、2、3、4、5、6、10、12、15、20、30和60。跟踪每个因子的数量 嵌套的1到1000之间的整数。嵌套完成后,您的程序应该知道 哪个整数影响最大。使用单独的for循环输出每个因子。 这是我的代码

public class program45{
    public static void main(String args[]){
        int count=0,count1=0,num1=0;
        for (int num=1; num<=1000; num++ ){
            for(int facnum=1; facnum<=num; facnum++){
                if(num%facnum==0){
                    count++;
                }
                if(count>count1){
                    num1=num;
                    count1=count;
                    count=0;
                }
            }
        }
        System.out.println(num1+" has the most factors");
        System.out.print("they are ");
        for(int facnum1=1; facnum1<=num1; facnum1++){
            if (num1%facnum1==0){
                System.out.print(facnum1+", ");
            }
        }
    }
}

已经尝试将第二个if语句放在嵌套的if中。

1 个答案:

答案 0 :(得分:0)

   import React, { Component } from "react";
    import Component1 from "./component1";
    import Component2 from "./component2";


class App extends Component {

    constructor(props) {
        super(props);

        // this.toggle = this.toggle.bind(this);
        this.state = {
            tabs: [{
                id: '1',
                component: <Component1/> ,
                title: 'Component1',
                description: 'This is it'
              }, {
                id: '2',
                component: <Component2/>,
                title: 'Component2',
                description: 'This is another one'
              }],
              activeId: '1'
        };

        this.switchState = this.switchState.bind(this);
    }

    switchState(activeId) {
        this.setState({ activeId });
    }
    render() {
        return (


                                <div className={styles.col}>
                                    <div className={styles.card}>
                                        <div className={styles.cardBody}>
                                            <div className={styles.row}>
                                                <div className={styles.col12}>
                                                    <div
                                                        className={`${
                                                            styles.positionRelative
                                                        } ${styles.formGroup}`}>
                                                        <div
                                                            style={{
                                                                fontWeight:
                                                                    "bolder",
                                                                color: "#7192a6",
                                                            }}>
                                                            <span
                                                                className={
                                                                    this.state
                                                                        .activeId === '1'
                                                                        ? `${
                                                                            styles.switchState
                                                                        }`
                                                                        : `${
                                                                            styles.switchState
                                                                        } ${
                                                                            styles.unselected
                                                                        }`
                                                                }
                                                                onClick={() => {
                                                                    this.switchState();
                                                                }}>
                                                                Component1{" "}
                                                            </span>
                                                            /
                                                            <span
                                                                className={
                                                                    this.state
                                                                        .activeId === '2'
                                                                        ? `${
                                                                            styles.switchState
                                                                        } ${
                                                                            styles.unselected
                                                                        }`
                                                                        : `${
                                                                            styles.switchState
                                                                        }`
                                                                }
                                                                onClick={() => {
                                                                    this.switchState();
                                                                }}>
                                                                {" "}
                                                                Component2
                                                            </span>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <div className={styles.row}>
                                                <div className={styles.col12}>
                                                    <Component1  
                                                    />
                                                    <Component2

                                                    />
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>


                {/* Caption begins */}
                <span className={styles.priceCalculatorSeparator} />
                <div className={styles.priceCalculatorComment}>
                    <h1 className={styles.title}>{tabs.title}</h1>
                    <hr className={styles.hr} align="left" />
                    <div className={styles.par}>
                        {tabs.description}
                    </div>
                </div>
            </div>

        );
    }
}

export default App;