If you can't do this by making a mistake in Java testing at that time, it's not programming thinking! I remembered that I kept being told that I made it into C # and output it.
public static void Main(string[] args){
int[] nums=new int[10];
for(int i=0;i<nums.Length;i++){
nums[i]=i/2;
}//0,0,1,1,2,2,3,3,4,4
int sum=0;
int index=0;
for(;index<nums.Length;index++){
sum+=nums[index];
if(sum > 10){
break;
}
}
Console.WriteLine(index); //1
int[] data={3,5,8,1,2};
var result=data.Where(n=>n%2==0).Select(n=>n*n).Sum();
Console.WriteLine(result); //2
data.OrderByDescending(n=>n).ToList().ForEach(Console.Write); //3
Difference from Java
public static void Main(string[] args){ //String in main
nums.Length //length
In the first for statement, the values of the array num are added in order from index 0, and the index number when the total exceeds 10 is returned. 2 is a lambda expression, but just sum the multiplication of even numbers with the query statement as a hint. 3 is stored in a list and output in descending order by the For Each method.
Because 1 is 0,0,1,1,2,2,3,3,4,4 Answer: 7
2 is 8 * 8 = 64 2 * 2 = 4 Answer: Total of aggregates 68
3 is 85321 (no comma)
Besides, it will be Java, but let's display the diamond or the pyramid ...
Recommended Posts