5:44 PM int rows = (int) Math.pow(2, total-operands) Answer 1 of 1 Done System.o
ID: 3734859 • Letter: 5
Question
5:44 PM int rows = (int) Math.pow(2, total-operands) Answer 1 of 1 Done System.out.print(operands[i)+ " ") System.out.println(expression) System.out.println" for (int o-0 o rows; o+) operands-value = new int[total-operands]. int k-0; for (intj-total-operands-1;js=0;j-) { operands-value(k++] = (0(int) Math. pow(2, j))%2; System.out.print(((o(int) Math.pow(2.))%2-= l ?"I'·.F') + " "); Stringl] operation new String[total operands]; int operation count -0; fortint i-0; i= 'a. && expression.charAt(i) = 'A, && expression.charAt(i)Explanation / Answer
In first line of code we are initializing a value of 'rows' as 2total_operands. Let assume total_operands are x then row=2x. In the next for loop we are initializing the array call operands with the size if rows. We are running second for loop with the size of rows to r=traverse each and every element of operands array. Inside the loop we are declaring a array called operand_value. And declared variable k which is initialised to 0. Inside the second for loop we are running another for loop but in reverse order with the size of total_operands to insert the values into that array by some calculations. outer for loop runs from 0,1,2......rows (represented by o) inner for loop runs from total_opetands-1, total_operands-2,.........0 (represented by j) TO insert a element to operands_value in 0th index we calculating 2j (after calculating 2j we type cast it into int)and dividing it with current o value which is 0 after that for the result we do mod 2 and inser it into first index of operand_values. Like that for every value in outer for loop inner for loops runs total_operands times while inserting parallely we check wether the value is 0 or 1 by using the ternary condition in Syste.Out.Println line. If the value 1 we print T or else we print F. Next we are creating another string array operation with the size of total_operands. We are running a for loop from 0 to length of the expression Inside that loop we are checking type of each character in the expression. In the first if condition we are checking that the given character is any kind if alphabet or not if its not then we enter into the else part. In else part if it is not alphabet we are inserting that element to operation array in the corresponding index. in else part we have another for loop to check the next element to that is alphabet or not. If its not alphabet we insert into the operation array. To end of that entire for loop which we run from 0 to lenght of expression, in the operation array we are inserting every element in the expression to operands array which are not alphabets. And total lenght of that array become operand_count. Next we compare if the charcter in the operation array is '' then we initialize operator with '&' , if the character is '' we initialize operator with '|'.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.