In a few English sentences, provide an algorithm for performing a simple task su
ID: 3781724 • Letter: I
Question
In a few English sentences, provide an algorithm for performing a simple task such as making a phone call, making a sandwich, or some other short task with only a few steps. In one to two short sentences, explain what a variable is and what it is used for. In one to two short sentences, explain what a String is and what it is used for. Given the following declarations, evaluate the expressions labelled a-g below: int age = 23; double pi = 3.1415; double radius = 3; String the Bard = "Now is the winter of our discontent"; char letter = 'd'; pi * radius * radius "The quote is " + theBard.length() + " characters in length" theBard.indexOf("our") theBard.charAt(6) age * 2 age % 3 (age % 30) - (age/30) Given the following piece of Java code, give the output that would be displayed by the last line of the code: int enigma = 12; int enigma2 - enigma * 2; System.out.printIn("The value of enigma is: "+enigma);Explanation / Answer
Answer - 1
Procedure MakePhoneCall
At first take the phone and check the contact list for the number, if the number
is saved in the contact list then just call the number , otherwise dial the number by entering
it in the phone and call the number
End_MakePhoneCall
Answer - 2
variable - is a symbolic name of memory location which is used to store value.
Answer - 5
The value of enigma is: 12
Answer - 3
string - is a sequence of characters
Answer - 4
a. pi * radius * radius = 3.1415 * 3 * 3 = 3.1415 * 9 = 29.2735
b. String theBard = "Now is the winter of our discontent";
length of string theBard is 35
Thus , ("The quote is "+theBard.length()+" characters in length") will generate (The quote is 35 characters in length)
c. theBard.indexOf("our"), this function will generate 21 as starting index of substring "our" is 21 and indexing starts from 0
d. theBard.charAt(6), will generate ' ' (space character) as this function returns the character of the string for the specified index
e. age * 2 = 23 * 2 = 46
f. age % 3 = 2 as if we divide 23 by 3 the 2 remains as remainder, here % is the remainder operator
g. (age % 30) = (23 % 30) = 23 as if we perform integer division then after dividing 23 by 30, 23 remains as remainder
(age / 30) = 0 as age is also integer then here integer division will takes place and result will be 0 (zero)
Thus (age % 30) - (age / 30) = 23 - 0 = 23
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.