如何理解我的Java循环的哪一部分输出星号?

时间:2018-11-25 14:48:00

标签: java loops methods

谁能告诉我哪一部分输出any符号前面的数字?是方法还是输出?

import Autosuggest, { ItemAdapter } from 'react-bootstrap-autosuggest'

        <Autosuggest
             datalist={this.state.formData.cname.list}
             itemAdapter={CustomerListAdaptor.instance}
             placeholder="Enter CustomerName"
             valueIsItem={true}
             value={this.getInputValFromCustomSources('cname')}
             onChange={ (val) => this.autuSuggestionControls.onChange(val, 'cname') }
             ref = {(domElm) => { this.domElmns.cname = domElm; }}
             onKeyUp = {(e) => this.handleKeyUp(e, {currElmKey: 'cname', isCustomerNameInput: true}) }
             // onSelect = {(param) => this.autuSuggestionControls.onInputSelect(param, 'cname')}
             inputSelect = {(e) => this.autuSuggestionControls.inputSelect(e)}
             readOnly={this.props.billCreation.loading}
         />

1 个答案:

答案 0 :(得分:0)

您正在打印从方法返回的数字。您可以像这样更改它,以免打印该方法的返回值,

import java.util.*;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        System.out.println("enter number");

        int number = sc.nextInt();

        int i = 1;
        while (i <= number) {
            printLine(number);
            System.out.println();
            number--;
        }
        i++;

    }

    public static int printLine(int number) {
        for (int j = 1; j <= number; j++) {
            System.out.print("*");

        }
        return number;
    }
}

这是您打印方法返回的数字的部分,

System.out.println(printLine(number));

您还可以将该方法的类型更改为void,因为您无需返回该值