output:8
explanation:
in[] array = {1,4,3,6,8,2,5};
int sum =array[0];//now sum=1
for(int i=0;i<array.length;i++)
{
if(array[i] > sum)
sum=array[i];
//i=0
//array[0] > sum | 1 > 1 //if condition
fails
//i=1
//array[1] > sum | 4 > 1 //if condition is
true
//so, sum =array[1] = 4
//i=2
//array[2] > sum | 3 > 4 //if condition
fail
//i=3
//array[3] > sum | 6 > 4 //if condition is
true
//so, sum =array[3] = 6
//i=4
//array[4] > sum | 8 > 6 //if condition is
true
//so, sum =array[4] = 8
//i=5
//array[5] > sum | 2 > 8 //if condition
fails
//i=6
//array[6] > sum | 5 > 8 //if condition
fails
//so finally sum is 8
}
System.out.println(sum);//prints 8
What does the following code output? int[] array = { 1, 4, 3, 6, 8, 2,...
1. What is the output of the following code segment? int array[] = { 8, 6, 9, 7, 6, 4, 4, 5, 8, 10 }; System.out.println( "Index Value" ); for ( int i = 0; i < array.length; i++ ) System.out.printf( "%d %d\n", i, array[ i ] ); 2. What is the output of the following code segment? char sentence[] = {'H', 'o', 'w', ' ', 'a', 'r', 'e', ' ', 'y', 'o', 'u' }; String output = "The sentence...
PLEASE SOLVE THESE QUESTIONS Q.3.6 What does the following code output? int x = 8; int y = 2; while(x > 8) { X- y+=2; } System.out.println(y); Q.3.7 What does the following code output? System.out.println((2 + 3 - 5) * (3/3) + (5+5)); Q.3.8 What does the following code output? if((2 == 2) && (3 != 3) && ((5 + 1)==6){ System.out.println(true); else { System.out.println(false);
What is the result of the following program fragment: int[] array = { 1, 4, 3, 6 }; int what = 0; for ( int index=0; index < array.length; index++ ) { what = what + array[ index ] ; } System.out.println( what );
20) What is the output of the following segment of C code: int avg(int n, int* a); int main () { int array[4]={1,0,6,9}; printf("%d", avg(4, array)+ 1); system("pause"); return 0; } int avg(int n, int* a) { int i, sum=0; for (i=0;i<n;i++) { sum+=a[i]; } return sum/n; } a) 16 b) 5 c) 4 d) 8 21) What is the output of the following segment of C code: int x = 2; int y = 3;...
please illistrate a UML diagram for the following code bellow, it should have 3 rows, 1 colum like the one bellow, first box should have the class name, second box is for class attributes, and third box should have the class operations/methods and please put a (+) for public and a (-) for private example: class +-attributes +-Operations Also make a JAVADOCs, but not generated by a compiler, to explain what is going on in the code import java.util.Random; public...
1. (TCO 1) What is the output of the following C++ code? int list[5] = {0, 5, 10, 15, 20}; int j; for (j = 0; j < 5; j++) cout << list[j]; (Points : 4) 0 1 2 3 4 0 5 10 15 0 5 10 15 20 5 10 15 20 Question 2.2. (TCO 1) What is stored in alpha after the following code executes? int alpha[5] = {0}; int j; for (j = 0; j...
QUESTION Z What is the output of the following code: int list[] = {1, 2, 3, 4, 5, 6}; for (int i = 1; i < 6; i++) list[i] = list[i - 1]; for (int i = 0; i < 6; i++) cout << list[i] << ""; 0 1 2 3 4 5 6 0 2345 61 0 111111 0 234 566
Given an array has been declared previously using the code: int a[] = {2, 4, 6}; What is the output of the code: System.out.println(a[3]); ? a) 6 b) 4 c) no output, there will be an error d) 2
QUESTION 8 What (if anything) will be the output of the following code: int count = 3; while (count++ <= 6) { System.out.print(++count + " "); } 3 4 5 6 4 5 6 7 3 4 5 6 7 5 7 4 6 The above code contains a syntax error and will not run. 8 points QUESTION 9 What (if anything) will be the output of the following code: int count = 0; while (count < 5) {...
(a)How many times does the code snippet given below display "Hello"? int x = 1; while (x != 15) { System.out.println ("Hello"); x++; } (b)What is the output of the following code fragment? int i = 1; int sum = 0; while (i <= 5) { sum = sum + i; i++; } System.out.println("The value of sum is " + sum); Quie 2 What is the output of the following snipped code? public class Test {...