Question

DESCRIPTION: The purpose of this question is offload processing from the main method to a static...

DESCRIPTION:

The purpose of this question is offload processing from the main method to a static helper method. You will be given the main method. Do not alter this code.

Your goal is to write a new method called oddOneOut, which will accept a String, and print it in out every other letter.

For example, if the String was "abcdefghijk", the oddOneOut method will return "acegik" .

METHOD INPUT:

  • A string

METHOD PROCESSING:

  • Do not alter the  main method.
  • Complete the static method oddOneOut:
    • This method accepts a String as an argument and returns a string with that includes every other letter of the original string (i.e. removes all characters with an odd index).

RETURN VALUE:

  • Return a string containing every other letter (starting with the first) of the original string.

Sample input/output:

ARGUMENT INPUT RETURN VALUE

I really like ice cream!

Iral ieiecem

ABCDEFGHIJKLMNOPQRSTUVWXYZ

ACEGIKMOQSUWY

Angela Siegel

Agl igl

Given code:

import java.util.Scanner;

public class Question1 {
  
/**
* oddOneOut method
*/
  
  
  
  
  
  
  

   /*=====================================
   || DO NOT ALTER CODE BELOW THIS LINE ||
   =====================================*/
  
public static void main(String[] args) {

//creating a scanner, reading input
Scanner in = new Scanner(System.in);

String s = in.nextLine();
  
//calling the oddOneOut() method
System.out.println(oddOneOut(s));

}
}

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

`Hey,

Note: If you have any queries related to the answer please do comment. I would be very happy to resolve all your queries.

import java.util.Scanner;

public class Question1 {
  
/**
* oddOneOut method
*/
  
public static String oddOneOut(String s)
{
String ns="";
for(int i=0;i<s.length();i=i+2)
{
ns=ns+String.format("%c",s.charAt(i));
}
return ns;
}
  
  

  
  
  

/*=====================================
|| DO NOT ALTER CODE BELOW THIS LINE ||
=====================================*/
  
public static void main(String[] args) {

//creating a scanner, reading input
Scanner in = new Scanner(System.in);

String s = in.nextLine();
  
//calling the oddOneOut() method
System.out.println(oddOneOut(s));

}
}

.Execute > Share Source File STDIN L.lı Result 8 $javac Questionl.java Sjava -Xmx128M -Xms 16M Question1 Iral ieiecem { 9 pub

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
DESCRIPTION: The purpose of this question is offload processing from the main method to a static...
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
  • Java, please. Work based on the code above. DESCRIPTION: The purpose of this question is offload...

    Java, please. Work based on the code above. DESCRIPTION: The purpose of this question is offload processing from the main method to a static helper method. You will be given the main method. Do not alter this code. Your goal is to write a new method called oddOneOut, which will accept a String, and print it in out every other letter. For example, if the String was "abcdefghijk", the oddOneOut method will return "acegik" METHOD INPUT: • A string METHOD...

  • DESCRIPTION: You will be given a 1-D array, called wordFun, of Strings. The array has an...

    DESCRIPTION: You will be given a 1-D array, called wordFun, of Strings. The array has an unknown number of cells filled with data. As before, the array will already be filled with strings, some of which contain the string "Angela". You will create a method called countItUp which returns and integer array containing the number of times each of the letters in my name occur within the strings within this array. For example, if the input array was wordFun =...

  • DESCRIPTION: You will be given a 1-D array, called wordFun, of Strings. The array has an...

    DESCRIPTION: You will be given a 1-D array, called wordFun, of Strings. The array has an unknown number of cells filled with data. As before, the array will already be filled with strings, some of which contain the string "Angela". You will create a method called countItUp which returns and integer array containing the number of times each of the letters in my name occur within the strings within this array. For example, if the input array was wordFun =...

  • 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);...

  • DESCRIPTION: You will be given a 2-D string array, called matrix. The array has an unknown...

    DESCRIPTION: You will be given a 2-D string array, called matrix. The array has an unknown number of cells filled with data. Your goal is to iterate through the 2-D array and keep a count of how many cells contain the string "Angela". INPUT: All input has been handled for you: A filled 2-D string array. PROCESSING: Determine the number of rows in the array matrix Determine the number of columns in the array matrix Use nested loops to iterate...

  • In this same program I need to create a new method called “int findItem(String[] shoppingList, String...

    In this same program I need to create a new method called “int findItem(String[] shoppingList, String item)” that takes an array of strings that is a shopping list and a string for an item name and searches through the “shoppingList” array for find if the “item” exists. If it does exist print a confirmation and return the item index. If the item does not exist in the array print a failure message and return -1. import java.util.Scanner; public class ShoppingList...

  • Below is the code from LE 6.2 that LE 7.1 is referring to. import java.util.Scanner; public...

    Below is the code from LE 6.2 that LE 7.1 is referring to. import java.util.Scanner; public class lastNameLE62 { private static Scanner in = new Scanner(System.in); private static int size; public static void arraySize() { System.out.printf("How many sports are you interested in? "); size = Integer.parseInt(in.nextLine()); } public static String[] setFavoriteSports() { String []favSports = new String[size]; for(int i=1; i<=size; i++) { System.out.printf("Enter sport #%d: ", i); favSports[i-1] = in.nextLine(); } return favSports; } public static String[] setFavoriteTeams(String[] sports) {...

  • Write a public static method named getMaxOf2Ints that takes in 2 int arguments and returns the...

    Write a public static method named getMaxOf2Ints that takes in 2 int arguments and returns the Maximum of the 2 values Write a public static method named getMinOf2Ints that takes in 2 int arguments and returns the Minimum of the 2 values Write apublic static method named getMaxOf3Ints that takes in 3 int arguments and returns the Maximum of the 3 values Write a public static method named getMedianOf3Ints that takes in 3 int arguments and returns the Median Value...

  • //LinkedList import java.util.Scanner; public class PoD {    public static void main( String [] args )...

    //LinkedList import java.util.Scanner; public class PoD {    public static void main( String [] args ) { Scanner in = new Scanner( System.in ); LinkedList teamList = new LinkedList(); final int TEAM_SIZE = Integer.valueOf(in.nextLine()); for (int i=0; i<TEAM_SIZE; i++) { String newTeamMember = in.nextLine(); teamList.append(newTeamMember); } while (in.hasNext()) { String removeMember = in.nextLine(); teamList.remove(removeMember); }    System.out.println("FINAL TEAM:"); System.out.println(teamList); in.close(); System.out.print("END OF OUTPUT"); } } =========================================================================================== //PoD import java.util.NoSuchElementException; /** * A listnked list is a sequence of nodes with...

  • 5. Write a static method "f(n)" in the space provide, that returns O if n is...

    5. Write a static method "f(n)" in the space provide, that returns O if n is even, and if n is odd, returns 1 or -1 according as n is greater than or less than 0. importjava.util.Scanner; public class Q_05 Your "f(n)" method: public static void main(String args[]) mana int n; Scanner input = new Scanner(System.in); System.out.print("Please enetrn: "); n=input.nextInt(); System.out.println(f(n)); "Method f(n)" 7. Write a static method "max" in the space provide, that returns the maximum value from 3...

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