Note: The answers to the following questions should be typed in the block of com
ID: 3880607 • Letter: N
Question
Note: The answers to the following questions should be typed in the block of comments in the Assignemnt2-java file. Please make sure they are commented out (green). Type them neatly and make them easy to read for the graders. d myString with the value-coding is fun!" answer questions! through 3. Question #1 (1pt): write a statement that will output (System.out) the number of characters in the string. Question #2 (1pt): write a statement that output the index of the character ' d' Question #3 (1 pt): write a statement that uses the original string to extract the new string "fun" and prints it to the screen Question # 4 (2 pts): what do the following expressions evaluate to in Java given int x = 3, y = 6; a) x=-y/2 Question # 5 (1 pt): what does the following statement sequence print? string str = "Harry Potter" int n = str.length(); String mystery = str.substring(0,1) + str.substring(n-1, System.out.println(mystery); n);Explanation / Answer
class Main { public static void main(String[] args) { // declaring variable String myString = "Coding is fun!"; // printing it's length System.out.println(myString.length()); } } // Output: 14 class Main { public static void main(String[] args) { // declaring variable String myString = "Coding is fun!"; // printing index of d System.out.println(myString.indexOf("d")); } } // Output: 2 class Main { public static void main(String[] args) { // declaring variable String myString = "Coding is fun!"; // printing fun using substring method System.out.println(myString.substring(10,13)); } } // Output: fun class Main { public static void main(String[] args) { // a: 3 == 6/2 is correct int x = 3, y = 6; System.out.println(x == y/2); // b. x%2 == 0 is false and y%2=6%2==0 is true // since it is OR condition, false or true is true only x = 3; y = 6; System.out.println(x%2 == 0 || y%2 == 0); // c. x-y < 0 is 3-6=-3Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.