Computer science JAVA. Please help me with those questions, and explain the answ
ID: 3745145 • Letter: C
Question
Computer science JAVA.
Please help me with those questions, and explain the answers as much as possible.
Code Analysis 1. (2 points) Given the following Java code fragment while( n > 0 )4 System.out.println("Do it"); n=n-2; (a) How many times does the string Do it print when n - 16? (b) How many times when n 32? 2. (2 points) Given the following Java code fragment for( int row = 0; row > 1; (a) How many times does the string Party Cannon print when n-2°? (b) How many times when n -204? 4. (4 points) Given the following Java code fragment: private int nigma(int value)( if( valueExplanation / Answer
Answer
1 (a) n = 16 : prints 8 times
1 (b) n = 32 : prints 16 times
2 (a) n = 16 : prints 256 times
2 (b) n = 32 : prints 1024 times
Explanation
1. Every time number is decreased by 2. So, it prints for n/2 times
16/2 = 8 and 32/2 = 16
2. 2 loops are running for n times each which will lead to n*n statements printed
16*16 = 256 and 32*32 = 1024
4 sub parts at a time please. Policy of Chegg
Answer
1 (a) n = 16 : prints 8 times
1 (b) n = 32 : prints 16 times
2 (a) n = 16 : prints 256 times
2 (b) n = 32 : prints 1024 times
Explanation
1. Every time number is decreased by 2. So, it prints for n/2 times
16/2 = 8 and 32/2 = 16
2. 2 loops are running for n times each which will lead to n*n statements printed
16*16 = 256 and 32*32 = 1024
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.