我需要帮助来编写代码,以找到序列中两个整数之间的最大差值

我需要编写代码来查找序列中两个整数之间的最大差。用户应该连续10天输入股票价格,程序会告诉您每天最大的变化。我被卡住了。


import java.util.Scanner;


public class Change {


 public static void main (String [] args) {

    final int days = 10;

     int largeDiff = 0; // largest difference

 Scanner sc = new Scanner(System.in);

 System.out.println("Enter a stock price:");


int price1 = sc.nextInt();


 int price2 = sc.nextInt();


 int diff1 = price1 - price2;


 for (int i = 1; i <= 8; i++) {

    int priceA = sc.nextInt();

    int priceB = sc.nextInt();


    int diff2 = priceA - priceB;


    if (diff2 > diff1) {

        diff2 = largeDiff;

    }

    else {

        diff2 = diff1;

    }


 }


 System.out.println(largeDiff);


}


}


慕标5832272
浏览 171回答 3
3回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java