MCQ on Java Programming With Answers set-11

1. If m and n are int type variables, what will be the result of the expression m%n when m=-14 and n=-3?A) 4B) 2C) -2D) -42. Consider the following codeif(number>=0) if(number>0) system.out.println("Number is positive");else system.out.println("Number is negative");What will be the output if number is equal to 0?A) Number is negativeB) Number is positiveC) Both A and BD) None of the above3. Consider the following code:char c='a';switch (c){ case 'a'; system.out.println("A"); case 'b'; system.out.println("B"); default; system.out.println("C");} For this code, which of the following statement is true?A) Output will be AB) Output will be A followed by BC) Output will be A, followed by B, and then followed by CD) Code is illegal and therefore will not compile4....

Write a Program in C to Find if a Number is Present in a List or not

Here is a C program to find if a number is present in a list of N numbers or not. In this program for loop is used to search a number from the list of numbers and array of numbers is used to insert numbers in a list. If the searched number is matched with any number in the list it throws to print it is presented in the list and if the searched number is not matched with any number in the list it throws to print it is not presented in the list. A C Program to Find if a Number is Present in a List of N numbers or notSteps: At first declare integers i, n, m, and array of integers a[10].Print the message to enter how many elements want...

C Program to Find the Sum and Average of Numbers Using Do-While Loop

In this program sum and average of of the given numbers are calculated using do-while loop.Do-while loop is a looping condition where statements are executed continuously until the condition validates and test the condition after having executed the statements within the loop.This means that do-while would execute its statements at least once, even if the condition fails for the first time.  Scanf() command is used here to allow enter the numbers and sum=sum+num; to sum the numbers within do-while loop. C Program to Find the Sum and Average of Numbers Using Do-While LoopSteps:  Declare two integers i and n and also initialize i...

Write a Program in C to Sort a List of Numbers in Ascending Order

In the program below nested  for loop is used to sort a list of  real numbers in ascending order. This program below asks to enter how many numbers want to sort and allow to enter the numbers to sort them in ascending order.The nested for loop in the program swaps the numbers if first number is greater than the next number. i.e. using (a[j]>a[j+1]) and        c=a[j];       a[j]=a[j+1];       a[j+1]=c; Here the value of a[j] copied to c and value of a[j+1] copied to a[j] and then value of c is copied to a[j+1]. Program in C to Sort a List of Numbers...

Write a Program in C to Calculate the Factorial Value of an Integer.

Here is a program in C to calculate the factorial value of an integer.The factorial of a number is the product of all the integers between 1 and that number.  For example factorial of 5 is 5*4*3*2*1. This can also be expressed as 5!=5*4!, where '!' stands for factorial.Hence factorial of a number can also be programmed using recursion. Here I have given two methods for calculating factorial of a number, using non-recursive function and using recursive function.Non-recursive function for calculating the factorial value of an integer Steps: Declare prototype for the function named factorial() used to calculate factorial value.Declare...

Write a Program in C to Copy a String to Another.

Here is a program in C to copy one string to another string using user defined function. Here two character arrays are defined then prompted to enter the strings and copied to the first string using while() function.Program in C to Copy a String to AnotherSteps:At first  declare two strings str1 and str2 and integers m, i, flag and j under main function.Prompt message to enter the strings and allow to enter strings using gets() function.Prompt the message and allow to enter the index where you want to insert in the first string.Copy second string to the first string using while() function.Print the first string to the screen.Code:#include...

C Program to Read Set of Real Numbers from Keyboard & Find the Maximum

To write a C program to read set of real numbers from keyboard and find the maximum among them, you can use a function which takes an array of real numbers and its size as arguments and return the maximum.Using this function you can write a program to read a set of real numbers from the keyboard and find the maximum number in the array.C Program to Read Set of Real Numbers and Find the MaximumSteps: Define a function max()  Under main() function, declare two integers i and n.Declare an array a.Prompt the message to the user to insert how many elements they want to enter using printf() and allow to enter using scanf().Prompt the message...

Write a Program in C to Determine Whether a Number is Prime or Not.

"A prime number is one, which is divisible only by 1 or itself."To determine whether a number is prime or not, we have to divide the number successively by all numbers from 2 to one less than itself.If remainder of any of these divisions is zero, the number is not a prime.If no division yields a zero then the number is a prime number.Program in C to Determine Whether a Number is Prime or NotSteps:Declare integers num and i inside main()Prompt the message allow the input using printf() and scanf()Test whether a Number is prime or not using while() function.Code:#include <stdio.h>int main() { int num, i; printf("Enter a number"); scanf...

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Cheap Web Hosting