How to Verify if the String Contains only Digits || Java Interview Question

preview_player
Показать описание
How to Verify if the String Contains only Digits!

~~Subscribe to this channel, and press bell icon to get some interesting videos on Selenium and Automation:

Follow me on my Facebook Page:

Let's join our Automation community for some amazing knowledge sharing and group discussion on Telegram:

WebServices API Automation Tutorials:

Follow me on my Facebook Page:

Let's join our Automation community for some amazing knowledge sharing and group discussion on Telegram:

Paid courses (Recorded) videos:
📗 Get My Paid Courses at
Paid courses (Recorded) videos:
-------------------------------

✔️SOCIAL NETWORKS
--------------------------------

Support My Channel✔️Or Buy Me A Coffee
--------------------------------
✔️Thanks for watching!
देखने के लिए धन्यवाद
Благодаря за гледането
感谢您观看
Merci d'avoir regardé
Grazie per la visione
Gracias por ver
شكرا للمشاهدة
Рекомендации по теме
Комментарии
Автор

if((s.replaceAll("[^0-9]", "")).length()==s.length()) {
System.out.println("Only digit");
}
else {
System.out.println("Other than digit");
}

This I learned from you, in your first lesson of this playlist, thanks for your video, learning many things that I don't know already..

Playlist-cjct
Автор

Thank you so much, Naveen for giving these videos. basically after seeing your videos really understood why for the testing interview too companies take coding interviews. Basically, as you are focussing on giving test cases that's what they want to see from us. Thanks again. I kind of tried to do this exercise in little different way and tried to run and include all test cases you showed. Please double-check though. package Collection;




public class StringContainsIntegerOrNot {


public static boolean isDigit(String str) {

String str1 = str.replaceAll("[^0-9]", "");
if ( str1== "" || str1==null)
return false;
else if (str1.equals(str))
return true;
else
return false;
}

public static void main(String[] args) {







"));












}


}

aradhikachawla
Автор

Thank you Naveen, this question has been asked a lot of times to me❤️😊👍🏻
Naveen rocks👌🏻👆🏻

jahangiralikhan
Автор

Using streams:
return str.char()
.mapToObj(e->(char)e)
.map(Character::isDigit)
.noneMatch(e -> e.equals(false));

Thank you Naveen!!

ajaykumarcheekati
Автор

Hi Naveen, Could you plz explain what is the difference between selenium 2.53 and 3.41 &
Which one should we use and why??

subhashreesahu
Автор

Hi Naveen, Another doubt is why do we use TestNG in our framework??
Can we replace it with any other tool?

subhashreesahu
Автор

Hi Naveen, why not just use regular expressions instead of using loops...

rajanrenator
Автор

Hi Naveen, need ur help here, my scripts are running intermittently sometimes it's get passed sometimes failed, even though my xpaths are right and when I debug it works ... What should I do

shwetatumbagi
Автор

Using integer Conversion and exception handling
private static boolean isNumeric(String str) {
try {
if (Integer.valueOf(str) >= 0) {
return true;
}
} catch (Exception e) {
return false;
}
return false;
}

sumitsaha
Автор

Sir Actually Telegram link has expired... please provide another working link...

siddisaidoki
Автор

From next time, do comment the problem statement at the beginning of the code so people can verify at each step what you are trying to solve.

RockyKarthik
Автор

Hi @Naveen, Here is an alternative simple code with try-catch & Integer Wrapper class, Please review it:

public static boolean isNumeric(String str) {
try {
Integer.parseInt(str);
return true;
} catch (Exception e) {
return false;
}
}

public static void main(String[] args) {

}

AmanSaxena-qktm
Автор

package

public class CheckNumeric {
public static boolean checkString(String str) {
for (int i = 0; i < str.length(); i++) {
if (!(str.charAt(i)>= 48 && str.charAt(i) <= 57))
return false;
}
return true;
}

public static void main(String[] args) {
String str = "12";
if (checkString(str))
System.out.println(str + " only contains number");
else
System.out.println(str + " does not contains number");
}

}

nikeshkumar-glfv