String to Number without using Integer.parseInt() method

preview_player
Показать описание

~~~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:

Naveen AutomationLabs Paid Courses:
Java & Selenium:

Java & API +POSTMAN + RestAssured + HttpClient:
Рекомендации по теме
Комментарии
Автор

Hello Naveen,

Informative video. Thank you.

Came across same interview question. Interviewer did not stop till normal positive number.

See if you can add below use cases to your code

1) Negative Numbers e.g. -12345
2) decimal numbers e.g. -123.5

Above use cases will definitely add value to this video.

tejassawant
Автор

Thanks Naveen. This was really good.
I have one question? I am confused on what level of Java we should know to crack the Interview. I have registered on LeetCode and keep on solving Java problems, but they are very tuff to solve and they always keep on talking about time complexity.
I have been working in Automation from past 2 years but have never worked on or have to worry about Time complexity. To be honest, I do not know that level of Java. Do I need to learn Java in-depth if I want to crack interview or Switch job?

amiteshtiwari
Автор

The logic for reversing a number is also like this....

pranupranav
Автор

Wonderful Naveen!!! ❤️ You definitely compel us to think...and explaining it in such simple way.

Q) what if we test for negative scenarios where string is appended with minus '-' sign.
In that does this code needs additional if like check for i[0] and may be maintain flag for negative do the conversion and then at end add sinage to number?
Do let us know. Thank you.

vinitp
Автор

Converting string to int explanation is really good. but i have a situation [ ReqQty = 2 in my excel value but it is in string and from UI side application is not allowing to enter string value in "ReqQty" it is allowing only Integer value . so here i am not able to provide value in 'ReqQty' field by 'SendKeys' method ] could you please help me in this regard

ameenmohammad
Автор

Naveen, can u explain the logic behind multiplying num with 10??

shazshaz
Автор

Hi Naveen, did not see the right platform to post this query hence posting here. This is re cypress. Is it possible to automate Google cloud platform using cypress?

elizaxlx
Автор

Sir how to print output in reverse order without changing for loop iterate element from 0 th index.

seemadolas
Автор

Hi Naveen, whats the font used in the IDE ?

Taheershaik
Автор

requesting you to put all the series in single container in udemy or any platform so easy to learn one by one

shrutitiwari
Автор

Is there any disadvantage/slowness of using Integer.parseInt??

sriramkukkadapu
Автор

I think you were missing your college and decided to code this once again. 😀

saurabhvikas
Автор

Another Solution
public static int parseInt(String str) throws Exception {
int n =0;
if(!isInt(str)) {
throw new Exception("Not able to convert to int");
}


for(int i=0;i<str.length(); i++) {
n= n*10+ str.charAt(i)-'0';

}
return n;
}

public static boolean isInt(String str) {
for(int i=0; i<str.length(); i++) {
{
return false;
}
}
return true;
}

mamtamehta