#22749: 新手java不太會:((((( 請問錯在哪呢?麻煩各位ㄌ


alan0927 (iiiqqe)

School : No School
ID : 110592
IP address : [61.223.119.62]
Last Login :
2021-01-05 21:20:04
b294. 經濟大恐荒 -- 板橋高中教學題 | From: [61.223.127.250] | Post Date : 2020-09-29 23:31

import java.util.Scanner;

public class ghj

{

public static void main(String[] args )

{

Scanner scanner = new Scanner(System.in);

int number = scanner.nextInt();

Scanner nb = new Scanner(System.in);

int number2 =scanner.nextInt();

int sum=0;

for(int i=1;i<number+1;i++)

{

sum=sum+i*i;

}

System.out.print(sum);

}

}

 
#22750: Re:新手java不太會:((((( 請問錯在哪呢?麻煩各位ㄌ


snakeneedy (蛇~Snake)

School : 國立高雄師範大學附屬高級中學
ID : 7661
IP address : [123.194.188.217]
Last Login :
2021-01-30 06:04:44
b294. 經濟大恐荒 -- 板橋高中教學題 | From: [123.194.188.217] | Post Date : 2020-09-29 23:42

題意要看仔細,是"價格x數量"而非"價格x價格",如果給的測資是

3
7 8 9

計算方式會是 1x7 + 2x8 + 3x9

 
ZeroJudge Forum