亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

算術進階3級

算術進階3級

烙印99 2024-01-28 17:35:26
這是算術級數級別 3。輸出尋找 2 個下一項。例如,輸入為:1, 4, 11, 24。尋找下2項,即45和76。如何解決?package Function;import java.util.Scanner;/** * * @author Lenovo */public class ArithmeticProgression {public static void main(String[] args){                int many;        Scanner keyboard=new Scanner(System.in);        System.out.print("Put many term: ");        many= keyboard.nextInt();        int term[]= new int [many];        int n= 0;        for(int z=0; z<many; z++){            n= n+1;            System.out.format("%d term"+ " is: ", n);            term[z] = keyboard.nextInt();        }        System.out.print("enter the next many terms: ");        int range= keyboard.nextInt();        int term2[] = new int[range+many];        for(int i = 0; i < many; i++){            term2[i] = term[i];        }        int b3= term2[many-1]-term2[many-2];        int b2= term2[many-2]-term2[many-3];        int b1= term2[many-3]-term2[many-4];        int c2= b3-b2;        int c1= b2-b1;        int d= c2-c1;        for(int q=0; q<range; q++){            b3= term2[many-1]-term2[many-2];            b2= term2[many-2]-term2[many-3];            b1= term2[many-3]-term2[many-4];            c2= b3-b2;            c1= b2-b1;            d= c2-c1;            int result= term2[many-1]+b3+c2+d;            System.out.println(result);            many++;             }    }}
查看完整描述

1 回答

?
慕標琳琳

TA貢獻1830條經驗 獲得超9個贊

在 q 循環中,您忘記在每一步更新 term2 數組:


    for(int q=0; q<range; q++){


        b3= term2[many-1]-term2[many-2];

        b2= term2[many-2]-term2[many-3];

        b1= term2[many-3]-term2[many-4];


        c2= b3-b2;

        c1= b2-b1;


        d= c2-c1;


        int result= term2[many-1]+b3+c2+d;


        System.out.println(result);


        term2[many] = result;  // you forgot this update

        many++;     

    }

這會生成列表 1, 4, 11, 24, 45, 76, 119, 176, 249, 340, 451, ...


查看完整回答
反對 回復 2024-01-28
  • 1 回答
  • 0 關注
  • 202 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號