Last active
August 29, 2015 14:21
-
-
Save takanakahiko/0c31027685d3b49a91fb to your computer and use it in GitHub Desktop.
配列の合計を返すメソッド
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Waaa{ | |
public static void main(String[] args ){ | |
int a[] = {1,2,3,4,5,6}; | |
System.out.println("配列Aの中身の合計は"+sum(a)+"です"); | |
int b[] = {1,2,3,4,5,6,7,8,9,6,4,3,3,3,5,45,45,56}; | |
System.out.println("配列Bの中身の合計は"+sum(b)+"です"); | |
if( daisyou( sum(a), sum(b) ){ | |
System.out.println("配列Aのほうが大きいです"); | |
}else{ | |
System.out.println("配列Bのほうが大きいか同じです"); | |
} | |
} | |
public static int sum(int[] hairetu){ | |
int n = 0; | |
for(int i = 0; i< hairetu.length; i++){ | |
n += hairetu[i]; | |
} | |
return n; | |
} | |
public static boolean daisyou(int x,int y){ | |
//1個目の数字のほうが大きければtrueを返すメソッド | |
if(x>y){ | |
return true; | |
}else{ | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment