1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
siniylev [52]
3 years ago
15

Write a Java method onlyDigits that takes a string as a parameter. The method should remove from the string all characters, whic

h are not digits, and return a string that contains only digits.
Computers and Technology
1 answer:
Stels [109]3 years ago
3 0

Answer:

public static String onlyDigits(String in){

    String digitsOnly = in.replaceAll("[^0-9]", "");

    return digitsOnly;

}

A Complete program is wrtten in the explanation section

Explanation:

public class TestClass {

   public static void main(String[] args) {

     String a = "-jaskdh2367sd.27askjdfh23";

       System.out.println(onlyDigits(a));

}

public static String onlyDigits(String in){

    String digitsOnly = in.replaceAll("[^0-9]", "");

    return digitsOnly;

}

}

The output: 23672723

The main logic here is using the Java replaceAll method which returns a string after replacing all the sequence of characters that match its argument, regex with an empty string

You might be interested in
Given two integer variables matricAge and gradAge, write a statement that gives gradAge a value that is 4 more than the value of
Natasha_Volkova [10]

Answer:

gradAge=matricAge+4;//Statement to give gradAge a value 4 more than matricAge.

Explanation:

This statement assigns the value stored in the matricAge variable with 4 added to it.So the value assigned to the gradAge is 4 more than value of matricAge.We have used assignment operator(=) to do this.Assignment operator assigns the value/variable's value written in the right to the variable to the left.

8 0
3 years ago
Rita wants to know the size of each image in a folder. Which view will help her find this information quickly?
vaieri [72.5K]
The correct answer would be details.

8 0
3 years ago
Select the correct answers
Mashutka [201]

Answer:

Use a mixture of External and Internal Links....

Explanation:

8 0
3 years ago
Explain how advanced analytics (e.g., Machine learning) helps the threat life cycle management. State the stage of the threat li
noname [10]

Advanced analytics may help to simulate the behavior of an infectious disease in epidemiology.

<h3>What is Advanced analytics?</h3>

Advanced analytics refers to the computation strategies that are able to manage a huge number of parameters to model a situation.

Advanced analytics is very useful in epidemiology because this approach allows for predicting the transmissible behavior of infectious diseases caused by pathogenic microorganisms (e.g., bacteria) and viruses.

In conclusion, Advanced analytics may help to simulate the behavior of an infectious disease in epidemiology.

Learn more about Advanced analytics here:

brainly.com/question/15007647

#SPJ1

8 0
2 years ago
What are building blocks? select three options.
mr Goodwill [35]

Answer:

Content that has been formatted

Content that is stored as templates

Content that is stored in galleries

Explanation:

These are the answers because that’s just what they are

7 0
4 years ago
Other questions:
  • What are some advantages and disadvantages to flooded coolers?
    8·1 answer
  • When you use your fingerprint on a reader attached to your computer to authenticate yourself as the legitimate computer user, wh
    6·1 answer
  • Spoken word and written word are different because what
    9·1 answer
  • Which of the following is the 1's complement of 10?
    10·2 answers
  • What is the most common concern with using variable frequency drives?
    6·1 answer
  • Routing protocols that enable routers to communicate beyond neighboring routers, allowing each router to independently map the n
    7·1 answer
  • E lvl:
    12·1 answer
  • SOMEONE HELP 60 POINTS!!!!! When creating business publications, these two factors must be determined before planning the layout
    8·2 answers
  • I need an If else statement that sorts three numbers from a file from least to greatest
    12·1 answer
  • 1. My grandma and I went shopping to look for old
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!