Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
Consider the following method:
public a(String s) {int v = 0;
for(int x = 1; x < s.length; x=x+1) {
if(s[x] == 'a' || s[x]=='e' || s[x] == 'i' || s[x] == 'o' || s[x] == 'u') {
v = v + 1;
}
}
return v;
}
Exactly how many lines of code (statements) are executed by the method a() in the worst case? Express your answer in terms of n, the length of the string s.
Hint: simplify your final answer as much as possible, and do not put spaces in your answer. Use juxtaposition for the multiplication operator, for example to write "nine times n" write "9n" not "9xn" or "9*n"; to write "four times (n+2)" write "4(n+2)", not "4x(n+2)" or "4*(n+2)". Do not write your answer in Big-O notation. Write the exact number of lines executed.
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- A pet shop wants to give a discount to its clients if they buy one or more pets and at least four other items. The discount is equal to 15 percent of the cost of the other items, but not the pets. Implement a method: public static void discount (double[] prices, boolean[] isPet, int nItems) The method receives information about a particular sale. For the ith item, prices[i] is the price before any discount, and isPet[i] is true if the item is a pet. Wite a program that prompts a cashier to enter each price and then a y for a pet orn for another item. Use a price of -1 as a sentinel. Save the inputs in an array. Call the method that you implemented, and display the discount.arrow_forward*JAVA* complete method Delete the largest valueremoveMax(); Delete the smallest valueremoveMin(); class BinarHeap<T> { int root; static int[] arr; static int size; public BinarHeap() { arr = new int[50]; size = 0; } public void insert(int val) { arr[++size] = val; bubbleUP(size); } public void bubbleUP(int i) { int parent = (i) / 2; while (i > 1 && arr[parent] > arr[i]) { int temp = arr[parent]; arr[parent] = arr[i]; arr[i] = temp; i = parent; } } public int retMin() { return arr[1]; } public void removeMin() { } public void removeMax() { } public void print() { for (int i = 0; i <= size; i++) { System.out.print( arr[i] + " "); } }} public class BinarH { public static void main(String[] args) { BinarHeap Heap1 = new BinarHeap();…arrow_forwardA palindrome is a string that reads the same forward and backward. For example,“deed” and “level” are palindromes. Write an algorithm in pseudocode that testswhether a string is a palindrome. Implement your algorithm as a static method inJava. The method should call itself recursively and determine if the string is apalindrome.Write a main method that reads a string from the user as input and pass it to thestatic method. You need to validate the string and make sure it contains only letters(no digits or special characters are allowed). The main method should displaywhether the string is a palindrome or not. a) Read the string from the user and validate it.b) Create a method that calls itself recursively and returns whether thestring is a palindrome or not.c) Include a test table with at least the following test cases:1. Invalid input. For example, string contains a number or specialcharacter.2. A valid string that is a palindrome.3. A valid string that is not a palindrome.arrow_forward
- 1. When you run the following code, what would happen?public class Question1 {public static void main(String arg[]){int i;int [] A = new int[10];int count = 0;int temp = 10;for (i=0; i < A.length; i++)if (A[i] < temp) count++;System.out.println(count);}}(a) It finds the smallest value and stores it in temp.(b) It finds the largest value and stores it in temp.(c) It counts the number of elements equal to the smallest value in list.(d) It counts the number of elements in list that are less than temp.arrow_forwardpreLabC.java 1 import java.util.Random; 2 import java.util.StringJoiner; 3 4- public class preLabC { 5 6- 7 8 9 10 11 12 13 14 15 16 17 18 19 20 } public static String myMethod(MathVector inputVector) { String vectorStringValue = new String(); // empty String object System.out.println("here is the contents object, inputVector: + inputVector); // get a String out of that MathVector object. Do it here. On the next line. // return the double value here. return vectorStringValue; "1 ▸ Compilation Description A MathVector object will be passed to your method. Return its contents as a String. If you look in the file MathVector.java you'll see there is a way to output the contents of a MathVector object as a String. This makes it useful for displaying to the user. /** * Returns a String representation of this vector. The String should be in the format "[1, 2, 3]" * * @return a String representation of this vector * @apiNote **DO NOT** use the built-in (@code Arrays.toString()} method. */…arrow_forwardConsider the following piece of code. (The numbers on the left margin denote line numbers.) line#01 public class funcRef {02 private int n;03 public funcRef (int m) {n = m;}04 public static void func (funcRef t) {t.n++;}05 public static void main (String [] args) {06 funcRef t1, t2;07 t1 = new funcRef(20);08 t2 = t1;09 System.out.print(t2.n);10 func(t1);11 System.out.print(t2.n);12 func(t1);13 System.out.print(t1.n);14 func(t2);15 System.out.print(t1.n);16 func(t2);17 System.out.print(t1.n);18 System.out.print(t1.n);19 return;20 }21 } Out of the following, tick the true statements and leave the false statements unticked.(More than one of the statements could be true. You get full marks only for marking all the statements correctly. There are no partial marks.) A. The output of the program will be 202022222222. B. When func(t1) is called in line…arrow_forward
- package lab06;;public class gradereport { public static void main(String[] args) { Scanner in = new Scanner(System.in);double[] Scores = new double[10]; for(int i=0;i<10;i++){ System.out.println("Enter score " + (i+1));scores[i]=in.nextdouble(); } for(int i=0;i<10;i++){ if (scores[i] >=80) System.out.println("Score " + (i+1) + " receives a grade of HD"); else if (scores[i]>=70) System.out.println("Score " + (i+1) + " receives a grade of D"); else if (scores[i] >=60) System.out.println("Score "+ (i+1) + " receives a grade of C"); else if (scores[i] >=50) System.out.println("Score " + (i+1) + " receives a grade of P"); else if (scores[i] >=40) System.out.println("Score " + (i+1) + " receives a grade of MF"); else if (scores[i] >=0) System.out.println("Score " +…arrow_forwardWrite a method that prints: 5 4 3 2 1 4 3 2 1 3 2 1 2 1 1 class Main {public static void main(String[] args) {}}arrow_forwardDetermine the output of the following code. public class MysterySplit{public static void main(String [ ] args){String myString = "Who likes chocolate candy for Halloween?";String [ ] words = myString.split("\\s");for (int i = 0; i < words.length; i++){String threeWords;if (i == words.length - 1)threeWords = words[i];else if(i == words.length - 2)threeWords = words[i] + " " + words[i + 1];elsethreeWords = words[i+2] + " " + words[i + 1] + " " + words[i];System.out.println(threeWords);}}}arrow_forward
- Consider the following method: public boolean isprefix(String s1, String s2) {int i = 0;if(s1.length > s2.length) return false;while(i < s1.length) {if(s1[i] != s2[i])return false;i++;}return true;} Exactly how many lines of code (statements) are executed by the method isprefix() in the worst case? Express your answer in terms of n, the length of the string s1. Hint: simplify your final answer as much as possible, and do not put spaces in your answer. Use juxtaposition for the multiplication operator, for example to write "nine times n" write "9n" not "9xn" or "9*n"; to write "four times (n+2)" write "4(n+2)", not "4x(n+2)" or "4*(n+2)". Do not write your answer in Big-O notation. Write the exact number of lines executed.arrow_forwardimport java.awt.*; public class TestRectangle {public static void main(String[] args) {Rectangle r1 = new Rectangle(5, 4, 10, 17);Rectangle r2 = new Rectangle(10, 10, 20, 3);Rectangle r3 = new Rectangle(0, 1, 12, 15);Rectangle r4 = new Rectangle(10, 10, 20, 3);System.out.println("r1 = " + r1);System.out.println("r2 = " + r2);System.out.println("r3 = " + r3);System.out.println("r2 equals r1? " + r2.equals(r1));System.out.println("r2 equals r2? " + r2.equals(r2));System.out.println("r2 equals r3? " + r2.equals(r3));System.out.println("r2 equals r4? " + r2.equals(r4)); System.out.println("r1 contains (6, 8)? = " + r1.contains(6, 8));System.out.println("r2 contains (6, 8)? = " + r2.contains(6, 8));System.out.println("r3 contains (6, 8)? = " + r3.contains(6, 8));System.out.println("r2 contains (30, 13)? = " + r2.contains(30, 13)); r1.intersect(r3);r2.intersect(r4);System.out.println("r1 intersect r3 = " + r1);System.out.println("r2 intersect r4 = " + r2);…arrow_forwardHelparrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education