30. What is the value of x after the following statements? int x x=15 % 4; A. 0
ID: 3917983 • Letter: 3
Question
30. What is the value of x after the following statements? int x x=15 % 4; A. 0 B. 3 C. 3.75 D. 4 E. 15 31. If you need to write a method that will compute the cost of some candy, where each piece costs 25 cents, which would be an appropriate method declaration? A. float CalculateCost (char name) B. float CaleulateCost (int countl) C. float CalculateCost int count D. char CalculateCost(int count) 32. What is wrong with the following switch statement? Scanner scan new Scanner (System. in) int ans system out.println(Type y for yes or n for non") ans scan.nextInt) switch (ans) case Y case TY system.out.print( "You said yes "); break case 'n' case N System.out.print( "You said noln") break default System.out.print( "Invalid answern") //End switch A. There are no break statements on two of the cases. B. ans is an integer data type C. Nothing D. break; is illegal syntax. 33. What are the valid indexes for the following array declaration? intiJ myArray new intl251: A. 0-24 B. 0-25 C. 1-24. D. 1-25 34. In a descending sort, which string would be first? A. "Wi11iam" B. "Mary" C. "1776" D. "Begin" E. "begin"Explanation / Answer
30) Answer is B i.e 3
Explanation: %(Module) operator between two integers will gives you the remainder. Here 15%4 implies the remainder value when you divide 15 with 4 .
31)Answer is B : float CalculateCost(int count)
Explanation: Here the input is number of candies i,e 'count' which should be Integer value ant the cost of each candy is 25cents. For total cost we need to multiply cost of each candy with the count of candies which will give you the integer value.
So return type can be int or long or float. In options we have return type as float or char so we can choose float as return type and count as int i.e option B
In option C: parameters are missing i,e incorrect syntax
32: Answer is B: ans is an integer datatype
Explanation:
<Datatype>
When we execute the program it asks as "Type y for Yes or n for no", if you enter y or n that will be assigned to variable "ans" which is declared as int variable. Assigning character value to an int variable will leads to an Exception. So declaring "ans" as int is a wrong.
33: A : 0-24
Explanation:
Array declaration syntax:
<Datatype> <array_name>[] = new <Datatype>[<array_size>]
so in the question an integer array of size 25 is declared.
Each element in the array is accessed via its index. The index begins with 0 and ends at (total array size)-1 . Here total array is 25 so index will start from 0 to 25-1 i.e 0 - 24
34: Answer is E: "begin"
Here all the given values are Strings. When we sort strings, internally it will compare the ascii values of the first characters in the every string. If two strings have same first character having same ascii value then it will compare the second character.
In this question the first characters of 5 Strings are:
"Willian" - W- 87
"Mary" - M - 77
"1776"- 1 - 49
"Begin" - B - 66
"begin" - b - 98
In descending sort, highest value will come first i.e b(98)- "begin" will come first, next "Willam","Mary","Begin","1776"
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.