第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何修復(fù)我的java代碼,不工作

如何修復(fù)我的java代碼,不工作

長(zhǎng)風(fēng)秋雁 2023-10-19 21:25:13
接受整數(shù)并將它們存儲(chǔ)在數(shù)組中并輸出其中最大數(shù)的程序。但以下代碼不起作用導(dǎo)入java.util.Scanner;公共類測(cè)試2 {public static void main(String[] args){    System.out.print("input the array'size : ");Scanner sc = new Scanner(System.in);int size = sc.nextInt();int arr[]=new int[size];System.out.print("input the array'value :");for(int i=0; i<size; i++){    int var = sc.nextInt();    arr[i] = var; }System.out.print("inputed value: ");for(int i=0; i<size; i++) {System.out.print(arr[i]+ " ");}int max = 0;for(int j=0; j<size; j++){    if(max<arr[j+1]){    max = arr[j];       }    else {    continue;    }}System.out.println("the largest number in array :"+ max);}}
查看完整描述

1 回答

?
POPMUISE

TA貢獻(xiàn)1765條經(jīng)驗(yàn) 獲得超5個(gè)贊

您不需要再次循環(huán)數(shù)組來查找最大值。通過獲取輸入本身,我們可以通過與每個(gè)輸入進(jìn)行比較來獲得最大數(shù)量。


public static void main(String[] args){

    System.out.print("input the array'size : ");

    Scanner sc = new Scanner(System.in);

    int size = sc.nextInt();

    int arr[]=new int[size];

    System.out.println("input the array'value :");

    int max = 0;

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

      int var = sc.nextInt();

      arr[i] = var; 

      if(var > max) {

          max = var;

      }

    }

    System.out.print("Input Array: "+Arrays.toString(arr));

    System.out.println("The largest number in array :"+ max);

 }


查看完整回答
反對(duì) 回復(fù) 2023-10-19
  • 1 回答
  • 0 關(guān)注
  • 98 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)