Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

30. What is the value of x after the following statements? int x x=15 % 4; A. 0

ID: 3918046 • 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).

the value of x wie be 3

Coz the modulo operator return the reminder

so when the you devide the 15 by 4 mean it will gives the reminder of 3 .

31). ans

float CalculateCost(int count)

here in this function float is the return data type and count is the parameter that will passed to the function.

so when you pass the parameter counts of candy to the funcion it will calculate the total price by multipling the 0.25*counts of candy so it will be the floating point value so we have to return the floating point value to callee.

32)B ans is the intgert data type

you have declare the ans as the integer and you take the input from the user as a character so switch case has the case with character and ans has intiger value.

33}A 0-24

every time you declare the array it index is start with the 0 and then 1 and then 2 and so on..

here the array size is 25 so index start with 0 and then 1 and then 2 upto 24 that is total 25 elements.

34)E "begin"

method sort characters based on their ASCII value, so the ascii value of the small b is greater then the W M B and 1 so begin is greater then the call so it would be the fiirst.

if you have any query related to this ans please ask me in the comment i am here for help. thanks.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote