Question

Consider this program segment int count; for (count = 2; count < value; count ++) {...

Consider this program segment

int count;

for (count = 2; count < value; count ++)

{

if (nums[count] < anyNumber)

            System.out.print (“ALWAYS”);

}

What is the maximum number of times that ALWAYS can be printed;

Homework Answers

Answer #1

Consider this program segment

int count;

for (count = 2; count < value; count ++)

{

if (nums[count] < anyNumber)

            System.out.print (“ALWAYS”);

}

What is the maximum number of times that ALWAYS can be printed;

Answer:

(value - 2) is the maximum number of times that ALWAYS can be printed;

EXPLANATION:

if value=6 then 4 is the maximum number of times that ALWAYS can be printed

if (nums[count] < anyNumber) is true for every time then gets (value - 2) is the maximum times

here value, nums[] and anyNumber are not declared here if not consider.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Java question Consider the following: 1 class SnoopDogg { 2 int count; 3 } 4 class...
Java question Consider the following: 1 class SnoopDogg { 2 int count; 3 } 4 class Test { 5 public static void main ( String [] args ) { 6 SnoopDogg myCount = new SnoopDogg (); 7 myCount.count = 0; 8 int times = 0; 9 increment( myCount, times ); 10 System.out.println( myCount.count ); 11 System.out.println( times ); 12 } 13 public static void increment (SnoopDogg sd, int times ) { 14 sd.count = sd.count + 1; 15 times =...
What is the output of the following code segment? public class Exception { ... static int...
What is the output of the following code segment? public class Exception { ... static int divider(int x, int y) { try { return x/y; } catch (ArrayIndexOutOfBoundsException a) { System.out.print("A"); return 1; } } static int computer(int x, int y) { try { return divider(x,y); } catch (NullPointerException b) { System.out.print("B"); } return 2; } public static void main(String args[]){ try { int i = computer (100, 0); } catch (ArithmeticException c) { System.out.print("C"); } } } ABC A...
2. Consider the following program written in C syntax: void swap(int a, int b) {   ...
2. Consider the following program written in C syntax: void swap(int a, int b) {    int temp;    temp = a;    a = b;    b = temp; } void main() {    int value = 2, list[5] = {1, 3, 5, 7, 9};    swap(value, list[0]);    swap(list[0], list[1]);    swap(value, list[value]); } For each of the following parameter-passing methods, what are all of the values of the variables value and list after each of the three...
convert the while loop into for loop x = int(input('Enter initial value: ')) count = 0...
convert the while loop into for loop x = int(input('Enter initial value: ')) count = 0 if(x<1): print('Error') exit() print('Initial value is: ',x,' ',end='') while(x!=1): if(x%2==0): x=x/2 else: x=3*x+1 count+=1 if(x!=1): rint('Next value is: ',int(x),' ',end='') else: print('Final value ',int(x),', ',end='') print('number of operations performed ',int(count),' ',end='') break
Consider the following definitions int[ ][ ] numbers = {{1, 2, 3},                                &
Consider the following definitions int[ ][ ] numbers = {{1, 2, 3},                                 {4, 5, 6} }; The following code below produces for (int row = numbers.length - 1; row >= 0; row -- ) { for (int col = 0; col < numbers[0].length; col ++) { System.out.print (numbers [row][col]); } }
Consider the following definitions int[ ][ ] numbers = {{1, 2, 3},                                &
Consider the following definitions int[ ][ ] numbers = {{1, 2, 3},                                 {4, 5, 6} }; The following code below produces for (int row = numbers.length - 1; row >= 0; row -- ) { for (int col = 0; col < numbers[0].length; col ++) { System.out.print (numbers [row][col]); } }
(C++ program) Use the code segment below to answer the two questions that follow. … int...
(C++ program) Use the code segment below to answer the two questions that follow. … int size = 0; cout << “Enter size: “; cin >> size; int sizeCode = size / 10; if (sizeCode == 0)    cout << “extra small”; else if(sizeCode == 1 )    cout << “small”; else if (sizeCode == 2)    cout << “medium”; else if (sizeCode == 3)    cout << “large”; else    cout << “extra large”; //end if … What would...
3. What will be the value of w after the following section of code executes: int...
3. What will be the value of w after the following section of code executes: int w = 4, q = 3; if (q > 5)       if (w == 7)           w == 3;       else            if (w > 3)               w = 1;            else               w = 0; A.0            B.1              C.2          D.3 4. What will be the value of b after the following section of code executes: int a = 4, b = 0; if (a...
Consider this function declaration: void quiz(int i) { if (i > 1) { quiz(i / 2);...
Consider this function declaration: void quiz(int i) { if (i > 1) { quiz(i / 2); quiz(i / 2); } cout << "*"; } How many asterisks are printed by the function call quiz(5)? Answer: The first time, i = 5 which is greater than 1, so the function is called twice with a value of (5/2) = 2. Since 2 > i, the function is called 4 times with a value of 1, and is not called anymore, since...
When the user enters 2 the following program segment should print the message “You’ve selected to...
When the user enters 2 the following program segment should print the message “You’ve selected to get an A”, however it always prints “You’ve selected to get a C”. Rewrite the code segment to behave properly, i.e., print the proper message: int selection; cout << “Please enter the grade you would like to receive “ << endl; cout << “1 = C, 2 = A”; cin >> selection; if (selection = 1) cout << “You’ve selected to get a C“...