Please Help *Urgent*
1 /* */
2 public class LabFinal
3 {
4 public static void main(String[] args) {
5 String mesg = "Try out this String.";
6 char[] hold = mesg.toLowerCase().toCharArray();
7 int p=0;
8
9 System.out.println(forwardSearch(hold,'s')); //output generated
11
10 System.out.println(forwardSearch(hold,'t')); //output generated
0
11 System.out.println(p=forwardSearch(hold,'t',2)); //output
generated 6
12 System.out.println(p=forwardSearch(hold,'t',p+1)); //output
generated 8
13 System.out.println(p=forwardSearch(hold,'z')); //output
generated -1
14 System.out.println(backwardSearch(hold,'s')); //output generated
13
15 System.out.println(backwardSearch(hold,'t')); //output generated
14
16 System.out.println(p=backwardSearch(hold,'t',13)); //output
generated 8
17 System.out.println(p=backwardSearch(hold,'t',p-1)); //output
generated 6
18 System.out.println(p=backwardSearch(hold,'z')); //output
generated -1
19
20 }
21
22 public static int forwardSearch(char[] array, char ch){
23 // write the code needed to implement this method
24 }
25
26 public static int forwardSearch(char[] array, char ch, int
startPosition){
27 // write the code needed to implement this method
28 }
29
30 public static int backwardSearch(char[] array, char ch){
31 // write the code needed to implement this method
32 }
33
34 public static int backwardSearch(char[] array, char ch, int
startPosition){
35 // write the code needed to implement this method
36 }
37
38 }
39
public class LabFinal {
public static void main(String[] args) {
String mesg = "Try out this String.";
char[] hold = mesg.toLowerCase().toCharArray();
int p = 0;
System.out.println(forwardSearch(hold, 's')); // output generated 11
System.out.println(forwardSearch(hold, 't')); // output generated 0
System.out.println(p = forwardSearch(hold, 't', 2)); // output generated 6
System.out.println(p = forwardSearch(hold, 't', p + 1)); // output generated 8
System.out.println(p = forwardSearch(hold, 'z')); // output generated -1
System.out.println(backwardSearch(hold, 's')); // output generated 13
System.out.println(backwardSearch(hold, 't')); // output generated 14
System.out.println(p = backwardSearch(hold, 't', 13)); // output generated 8
System.out.println(p = backwardSearch(hold, 't', p - 1)); // output generated 6
System.out.println(p = backwardSearch(hold, 'z')); // output generated -1
}
public static int forwardSearch(char[] array, char ch) {
// write the code needed to implement this method
for(int i=0; i<array.length ; ++i) {
if(array[i] == ch)
return i;
}
return -1;
}
public static int forwardSearch(char[] array, char ch, int startPosition) {
// write the code needed to implement this method
for(int i=startPosition; i<array.length ; ++i) {
if(array[i] == ch)
return i;
}
return -1;
}
public static int backwardSearch(char[] array, char ch) {
// write the code needed to implement this method
for(int i=array.length-1; i>=0 ; --i) {
if(array[i] == ch)
return i;
}
return -1;
}
public static int backwardSearch(char[] array, char ch, int startPosition) {
// write the code needed to implement this method
for(int i=startPosition; i>=0 ; --i) {
if(array[i] == ch)
return i;
}
return -1;
}
}
=================================================================
SEE OUTPUT
PLEASE COMMENT if there is any concern.
==============================
=================
Please Help *Urgent* 1 /* */ 2 public class LabFinal 3 { 4 public static void...
1. What is the output when you run printIn()? public static void main(String[] args) { if (true) { int num = 1; if (num > 0) { num++; } } int num = 1; addOne(num); num = num - 1 System.out.println(num); } public void addOne(int num) { num = num + 1; } 2. When creating an array for primitive data types, the default values are: a. Numeric type b. Char type c. Boolean type d. String type e. Float...
This is for a java program public class Calculation { public static void main(String[] args) { int num; // the number to calculate the sum of squares double x; // the variable of height double v; // the variable of velocity double t; // the variable of time System.out.println("**************************"); System.out.println(" Task 1: Sum of Squares"); System.out.println("**************************"); //Step 1: Create a Scanner object //Task 1. Write your code here //Print the prompt and ask the user to enter an...
In the Quiz class, the foo method has the following API : public static double foo( int i, string s, char c) how many arguments does foo take? is it 3 right? What is the output of this code sequence? int a = Math.min( 5, 8 ); System.out.println( a ); What is the output of this code sequence? System.out.print( Math.round( 3.5 ) ); What is the output of this code sequence? double d = Math.pow( 2, 3 ); System.out.println( d...
What will the following program display? public class checkpoint { public static void main(String urgs[]) { int n = 1776; doubled = 110.0901; System .out.println(n + \t + d); myMethod(n, d); System.out.println(n + \t + d); } public static void myMethod(int i, double x) { System.out.printing + \t + x); i = 1250; x= 199.99; System.out.println(i + \t" + x); } } Write the following two methods: i. compute Diameter; This method accepts the radius (r) of a circle, and...
[JAVA] help —————— ListArrayMain.java ——————- public class ListArrayMain { public static void main (String[] args) { ListArray L1 = new ListArray(); // constructs the list L1 L1.InsertBegin(2); L1.InsertBegin(3); L1.InsertBegin(7); L1.InsertBegin(15); L1.InsertBegin(5); L1.InsertEnd(666); L1.InsertAfter(1000,7); // Now, let's print out the array to verify the insertions worked. System.out.println("The items in the list are:"); for (int i = 0; i<= L1.lastCell; i++) { System.out.println(L1.a[i]); } System.out.println("The last cell number is: " + L1.lastCell); }// end main } ———————————- ListArray.java ———————————— public class ListArray...
Explain this java code, please. import java.util.Scanner; public class Program11 { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); final int maxSize = 128; String[] titles = new String[maxSize]; int[] lengths = new int[maxSize]; int numDVDs = 0; String op; op = menu(stdIn); System.out.println(); while (!op.equalsIgnoreCase("q")) { if (op.equalsIgnoreCase("a")) { if (numDVDs < maxSize) numDVDs = addDVD(titles, lengths, numDVDs, stdIn); } else if (op.equalsIgnoreCase("t")) searchByTitle(titles, lengths, numDVDs, stdIn); else if (op.equalsIgnoreCase("l")) searchByLength(titles, lengths, numDVDs, stdIn); System.out.println('\n');...
public class MovieAudience { public static void main(String[] args) { // input (hard-coded) Do not change. short[] agesOfAudience = { 39, 17, 67, 15, 56, 15, 92, 25, 62, 61, 79, 42, 85, 76, 58, 41, 22, 59, 83, 84, 72, 77, 31, 48, 44, 19, 43, 98, 96, 41, 64, 27, 60, 22, 6, 99, 67, 14, 31, 15, 97, 42, 87, 62, 79, 37, 46, ...
import java.util.Scanner; public class TriangleMaker { public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("Welcome to the Triangle Maker! Enter the size of the triangle."); Scanner keyboard = new Scanner(System.in); int size = keyboard.nextInt(); for (int i = 1; i <= size; i++) { for (int j = 0; j < i; j++) { System.out.print("*"); } System.out.println(); } for (int...
Analyze the following code: public class Test { private int t; public static void main(String[] args) { int x; System.out.println(t); } } t is non-static and it cannot be referenced in a static context in the main method. The program compiles and runs fine. The variable t is not initialized and therefore causes errors. The variable x is not initialized and therefore causes errors.
Analyze the following code: public class Test { private int t; public static void main(String[] args) { int x; System.out.println(t); } } The variable t is private and therefore cannot be accessed in the main method. The program compiles and runs fine. t is non-static and it cannot be referenced in a static context in the main method. The variablet is not initialized and therefore causes errors. The variable x is not initialized and therefore causes errors.