1.
What is output by the following code?
String s0 = "Java";
int i1 = s0.indexOf('a');
int i2 = s0.indexOf('a', i1);
int i3 = s0.indexOf('a', i1 + 1);
System.out.print(i1 + " " + i2 + " " + i3);
2.
What is output by the following code?
String s1 = "Java";
String s2 = "";
for (int i = 0; i < s1.length(); i++) {
s2 += s1;
}
System.out.print(s2);
Question 1
Answer:
The output of the given code is
1 1 3
variable i1 will hold the index of first occurrence of character 'a'. that is 1
variable i2 will also hold the index of first occurrence of character 'a'. that is 1
variable i3 will hold the index after first occurrence of character 'a'. that is 3
Question 2
Answer:
The output of the given code is
JavaJavaJavaJava
String s1 value is "Java'
we are appenind the string s1 to s2 based on the number of characters in string s1.
string s1 contains 4 characters so four "Java" words concatenated to s2.
1. What is output by the following code? String s0 = "Java"; int i1 = s0.indexOf('a');...
Language is Java. Thank you.It
is a review test and I will find out the rest if I just know that
answers.
1) What is the output of the following code: public class Test public static void main(String] args) [ String s1 new String("Java String s2 new String("Java) System.out.print( (s1 s2)(s1.equals (s2))) A) false false B) true true C) false true D) true false E) None of the above 2) Given the following program: public class Test f public static...
java
a. What is printed by the following code? Explain your answer by showing how you computed the values of pos, s1, s2 and 53. String str = "2900 Bedford Ave Brooklyn NY 12230-6843"; int pos = str.indexOf(" ", str.indexOf(" ", 'B') + 1); String si = str.substring(o, pos); System.out.println("pos: + post sl: + sl); pos - str.indexOf("B", pos+1); pos = str.indexOf("B", pos+1); String s2 = str.substring(pos, str. indexOf(" ", pos)): System.out.println("pos: + pos + + s2); String s3 =...
Write Java Programs to perform the following: 1. To create a new String object 2. To find the length of the string 3. Concatenation operator 4. To display the content in String array 5. A complete Java Program that incorporates the following String methods taught in class a. toUpperCase()) b. to LowerCase()) C. replace('0','A')) d. s1.length() e. compareTo(s1)) methods taught in class a. toUpperCase()) b. to LowerCase()) C. replace('0','A')) d. s1.length()) e. compareTo(s1)) f. 51.substring(4)) g. s2.substring(2,10)) h. s1.indexOf('g')) i....
JAVA 5) What is the output of the following code? int a = 70; boolean b = false; if(a >= 70) { System.out.print(1); if(b==true) { System.out.print(2); } } else { System.out.print(3); if(b==false) { System.out.print(4); } } System.out.print(5); 6) What is the output of the code above using these initial values? int a = 43; boolean b = false; 7) The following method is SYNTACTICALLY correct (meaning it will compile). True or false? public boolean method() { int value = 5;...
1. What is the output of the following code segment? int array[] = { 8, 6, 9, 7, 6, 4, 4, 5, 8, 10 }; System.out.println( "Index Value" ); for ( int i = 0; i < array.length; i++ ) System.out.printf( "%d %d\n", i, array[ i ] ); 2. What is the output of the following code segment? char sentence[] = {'H', 'o', 'w', ' ', 'a', 'r', 'e', ' ', 'y', 'o', 'u' }; String output = "The sentence...
Java beginners: Show how to invoke the method grunf so that it will return the String HOPE. public static String grunf(String s1, String s2, String s3) { String s = s1.substring(1,2); if (s1.length()>s2.length() && s2.compareTo(s3)<0 && s3.indexOf(s)>0) return s1.substring(0,1) + s2.substring(1); else return s1.substring(0,1) + s2.substring(0,1) + s1.substring(0,1); }
please evaluate the following code. this is JAVA a. class Car { public int i = 3; public Car(int i) { this.i = i; } } ... Car x = new Car(7), y = new Car(5); x = y; y.i = 9; System.out.println(x.i); b. class Driver { public static void main(String[] args) { int[] x = {5, 2, 3, 6, 5}; int n = x.length; for (int j = n-2; j > 0; j--) x[j] = x[j-1]; for (int j...
composed the following java code to read a string from a text file but receiving compiling errors. The text file is MyNumData.txt. Included the original java script that generated the output file. Shown also in the required output results after running the java program. I can't seem to search for the string and output the results. Any assistance will be greatly appreciated. import java.io.BufferedReader; import java.io.FileReader; import java.util.ArrayList; public class Main { public static void main(String[] args) { System.out.print("Enter the...
QUESTION 8 What (if anything) will be the output of the following code: int count = 3; while (count++ <= 6) { System.out.print(++count + " "); } 3 4 5 6 4 5 6 7 3 4 5 6 7 5 7 4 6 The above code contains a syntax error and will not run. 8 points QUESTION 9 What (if anything) will be the output of the following code: int count = 0; while (count < 5) {...