[Solved] Which is faster, for loop or LINQ

Neither. Using a loop has less overhead than LINQ, so that is a good start. Use the < operator in the loop condition, that is the standard way of writing such a loop, so it’s more likely that the compiler will recognise it and optimise it properly. Using Math.Pow to square a number is not … Read more

[Solved] How to correct segmentation fault with char * to int conversion

You are confusing pointers with arrays. A pointer just points; declaring a pointer does not reserve memory, it just creates a pointer variable pointing to some undefined place. Corrected program: char *recepcao(char *receber) { scanf(“%s”, receber); return receber; } int conversao(char *string) { int i, j; for(i=0; string[i]!=’\0′; ++i) { continue; } int var[100]; int … Read more

[Solved] How does a while loop inside a for loop work?

It will enter the for loop first when i = 0. Immediately after it will enter the while loop and continue running indefinitely as i will always be 0 and therefore < 3. You perhaps need to deal with j in the break condition of inner loop for avoiding an infinite loop. solved How does … Read more

[Solved] triangle of square numbers java

Only the second inner loop needs to be adjusted a little bit (changes in bold): for (int k = i; k >= 1; k–) { System.out.printf(” %2d”, k * k); } The first inner loop for indention runs n-i times, so the second inner loop have to do the rest: i..1. And you have to … Read more

[Solved] I need something like a multi dimensional array but using a for loop [closed]

Just use a regular for loop to iterate over all arrays at once: String[] item ={“[1]hotdog”, “[2]eggpie”,”[3]menudo”,”[4]pizza”,”[5]lumpia”}; int[] cost = {5, 10, 15, 20, 25}; int[] selling = {10,15,20,25,30,}; int[] qty = {2,4,6,8,10}; for (int i = 0; i < item.length; i++) { System.out.println(” ” +item[i]+”\t”+cost[i]+”\t\t”+selling[i]+”\t\t”+qty[i]); } I would recommend putting all of these fields … Read more