Frequently Asked Java Program 04: Java Program to Extract Numbers From String and Add

Hello Folks,

As part of Frequently Asked Java Programs In Interviews For Freshers And Experienced, in this post we will see a java program to extract numbers from a string.

Write a JAVA program for below requirements:

  1. Take an alphanumeric string from user.
  2. Verify if it is alphanumeric.
  3. If it is alphanumeric, extract all numbers present in string.
  4. Add all numbers and print it.

JAVA Program:

Output:

Please enter the alphanumeric string:
hfghfgh54545
String entered by user: hfghfgh54545
Sum of numbers found in hfghfgh54545 :23
==================================================================
Please enter the alphanumeric string:
%^&%dhfjf78
String entered by user: %^&%dhfjf78
%^&%dhfjf78 is not an alphanumeric.

#HappyCoding

Author: Amod Mahajan

My name is Amod Mahajan and I am an IT employee with 4+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went throw so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning