Question

JAVA: Excerpt B.A: Complete the implementation of the following method. The purpose of this method is...

JAVA:

Excerpt B.A:

Complete the implementation of the following method. The purpose of this method is to return true if and only if all the elements in the array are x. In other words, all elements in the array are the value x (replace -a- with right answer).

public static -a- allSame(int[] nums, int x){
for (int i = 0; i < -a-; i++){
if (nums[i] -a- x){
return -a-;
}
}
return -a-

}

Excerpt B.B: What is printed on the code below after calling myMethod2("UTEPMINERS"); - also, this code may need to be fixed:
public static void myMethod22(String str){
if (str length() == 0){
return;
}
else {
myMethod22(str.substring(1, str.length() - 1));
System.out.print(str.charAt(0));
}
}

Except B.C:

Complete the implementation of the method getNumVowels. This method receives a string as input and returns the number of vowels (a, e, i, o, u) in the string (replace -a- with right answer).

public static -a- getNumVowels (-a- s){
int count = -a-;
for (int i = 0; i < -a-; i++)
{
switch (-a-) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
-a-
}
}
return -a-;
}
  

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Excerpt B.A:


   public static boolean allSame(int[] nums, int x){
for (int i = 0; i < nums.length; i++){
if (nums[i] != x){
return false;
}
}
return true;
  
}

Excerpt B.B:

Output of : myMethod2("UTEPMINERS")

Output : SRENIMPETU // as this is the code to print string in reverse

CODE

public static void myMethod22(String str){
if (str.length() == 0){
return;
}
else {
myMethod22(str.substring(1, str.length())); // str.substring(1, str.length()) instead of str.substring(1, str.length()-1)
System.out.print(str.charAt(0));
}
}

Excerpt B.C:

public static int getNumVowels (String s){
int count = 0;
for (int i = 0; i < s.length(); i++)
{
char ch = s.charAt(i);
switch (ch)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
count++;
}
}
return count;
}

Add a comment
Know the answer?
Add Answer to:
JAVA: Excerpt B.A: Complete the implementation of the following method. The purpose of this method is...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Can you please translate this code from Java to C++; These are the only libraries i...

    Can you please translate this code from Java to C++; These are the only libraries i am allowed to use #include <iostream> #include <fstream> #include <sstream> #include <iomanip> #include <string> using namespace std; 1 /* Given a string, compute recursively (no loops) a new string where all * appearances of "pi" have been replaced by "3.14". public String changepi(String str) { if(str.length() <= 1) return str; if(str.substring(0, 2).equals("pi")) return "3.14" + changepi(str.substring(2)); 11 12 return str.charAt(0) + changepi(str.substring(1)); }

  • Hello, I have a assignment where the user inputs a word and the out will then...

    Hello, I have a assignment where the user inputs a word and the out will then tell the user how many of the five vowels are in the word so for example if I typed the word hello, it would output {0 1 0 0 0 } since there is only one vowel and that is e which is in the second row, I have most of it done, but I can't seem to figure out how to get the...

  • ​​​​​​public static int countCharacter(String str, char c) { // This recursive method takes a String and...

    ​​​​​​public static int countCharacter(String str, char c) { // This recursive method takes a String and a char as parameters and // returns the number of times the char appears in the String. You may // use the function charAt(int i) described below to test if a single // character of the input String matches the input char. // For example, countCharacter(“bobbie”, ‘b’) would return back 3, while // countCharacter(“xyzzy”, ‘y’) would return back 2. // Must be a RECURSIVE...

  • Explain in detail what the code below does: public class MyClass {       public static void...

    Explain in detail what the code below does: public class MyClass {       public static void main(String args[]) {              System.out.println(isUniqueChars("something"));       }       public static boolean isUniqueChars(String str) {             int checker = 0;                                                                                               for (int i = 0; i < str.length(); ++i) {                         int val = str.charAt(i) - 'a';                         if ((checker & (1 << val)) > 0) return false;                         checker |= (1 << val);             }             return true;...

  • in order to answer this question their is another two questions I posted  that relate so please...

    in order to answer this question their is another two questions I posted  that relate so please check but they are all one Part 1: Write a method with the signature public static int charAt(String str, int position) o Assume the String str consists of lower-case characters o if position <str.length the method returns the ascii value of str.charAt(position) - 96 o if position > str.length the method returns 0.

  • PrintArray vi Create a class called PrintArray. This is the class that contains the main method....

    PrintArray vi Create a class called PrintArray. This is the class that contains the main method. Your program must print each of the elements of the array of ints called aa on a separate line (see examples). The method getArray (included in the starter code) reads integers from input and returns them in an array of ints. Use the following starter code: //for this program Arrays.toString(array) is forbidden import java.util.Scanner; public class PrintArray { static Scanner in = new Scanner(System.in);...

  • Question 8 Identify the COMPILER ERRORS and EXCEPTIONS in this program. This program is saved in...

    Question 8 Identify the COMPILER ERRORS and EXCEPTIONS in this program. This program is saved in a file named MyProgram.java. public class MYProgram { public static void main( String [] args ) { int [] arrayOfIntegers = { 15, 20, 30 50, 60 }; for( int i = 0; i <= arrayOfIntegers.length(); i++ ) { System.out.println( "Hello" + i * 2 ) int i = 100 * arrayOfIntegers[ i ]; doSomething( i ); } } Public static void DoSomething( )...

  • JAVA // TO DO: add your implementation and JavaDoc public class SmartArray<T>{    private static final...

    JAVA // TO DO: add your implementation and JavaDoc public class SmartArray<T>{    private static final int DEFAULT_CAPACITY = 2;   //default initial capacity / minimum capacity    private T[] data;   //underlying array    // ADD MORE PRIVATE MEMBERS HERE IF NEEDED!       @SuppressWarnings("unchecked")    public SmartArray(){        //constructor        //initial capacity of the array should be DEFAULT_CAPACITY    }    @SuppressWarnings("unchecked")    public SmartArray(int initialCapacity){        // constructor        // set the initial capacity of...

  • Java StringNode Case Study: Rewrite the following methods in the StringNode class shown below. Leave all...

    Java StringNode Case Study: Rewrite the following methods in the StringNode class shown below. Leave all others intact and follow similar guidelines. The methods that need to be changed are in the code below. - Rewrite the indexOf() method. Remove the existing recursive implementation of the method, and replace it with one that uses iteration instead. - Rewrite the isPrefix() method so that it uses iteration. Remove the existing recursive implementation of the method, and replace it with one that...

  • How do I separate the method into different class? I try separate the testing and method...

    How do I separate the method into different class? I try separate the testing and method class into 2 different class. And when I test it, it said that the method is undefined. And it ask me to create the method in the main class. I don't know what is the problem. This is the access to the code https://repl.it/@Teptaikorn/test Thank you very much MazeSolver.java MazeTerster.... TwoDim AutoA... testfile.txt Main.java x > 0 N Binary TreeN... X LinkedBinary... Maze.java 1...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT