Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Finish the following code segment below with these following instructions: 1. Th

ID: 3758670 • Letter: F

Question

Finish the following code segment below with these following instructions:

1. This metod should loop over all of the values in the scanner and if the next value is not an int or a double, it should add that value to a string (with a space after it).

2. if it is an ant or a double, that value should be read, but not used or added to the string.

3. use the hasNextInt and the hasNextDouble methods to determine if the next value is an int or double.

4. return a string with all of the words from the scanner seperated by space.

public String cleanInput (Scanner input) {

// missing code goes here

return // missing code goes here;

}

Explanation / Answer

public static String cleanInput (Scanner input) {

       // missing code goes here

       String str = null;

      

       while (input.hasNext()) {

           if(input.hasNextInt()) {

               input.nextInt();

           } else if(input.hasNextDouble()) {

               input.nextDouble();

           } else {

               str+=input.next()+" ";

           }

       }

       return str;// missing code goes here;

   }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote