#Code that transform a string that may contain double values and letters in to integer

126 messages · Page 1 of 1 (latest)

torn jewel
#

Hi I am trying to make this code work, but when I input myname3 this it what it gives me, although I am asking for the length it doesn't give but the width is some
and the length is -1

tall heathBOT
#

This post has been reserved for your question.

Hey @torn jewel! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

torn jewel
idle rover
#

you didn't need to close the previous thread tbh

torn jewel
#

I added the if statement here aswell

torn jewel
idle rover
#

you didn't

torn jewel
idle rover
#

again, you didn't

torn jewel
#

it's closed man

idle rover
#

if you're trying to get an integer, why not just use parseInt

idle rover
idle rover
#

you can't get non-integers with the replace you have anyways, since the . gets removed

#

i don't think it'd make much sense to input 3.0 and get back 30

torn jewel
#

No I get 3.0

idle rover
#

you don't

torn jewel
#

when I had the length%0 == 0

#

It somehow worked but it reset me

#

let me show you

idle rover
torn jewel
idle rover
#

% does division. you can't do % 0

torn jewel
#

look man

#

this is what it does for me

idle rover
#

that's not what i said

#

im saying if you input 3.0, you get 30

#

do you want integers only or not

torn jewel
#

let me explain why i am doing this

idle rover
#

no, don't

#

do you want integers only or not

torn jewel
#

ok

#

yes integers only

idle rover
#

then use parseInt/hasNextInt/nextInt instead of all your double stuff

#

if you want integers, then use the integers

torn jewel
#

ok

#

one last thing

idle rover
#

don't attempt to fix the given value, just treat it as is and if it doesn't work then it doesn't work and prompt the user again

torn jewel
#

why does my program work when I say length%0 == 0

idle rover
#

you're doing % 1

#

oh huh you are

torn jewel
idle rover
#

didn't read the entire thing

torn jewel
#

only when I say %0 it works

idle rover
#

that's because you're short-circuiting and it never actually evaluates teh % 0

torn jewel
#

when I put %1 it doesn't

idle rover
#

/run

System.out.println(1 % 0);
urban needleBOT
#

@idle rover I only received java(15.0.2) error output

Exception in thread "main" java.lang.ArithmeticException: / by zero
	at temp.main(file0.code.java:2)
torn jewel
#

ok so why doesn't it work when I put %1

idle rover
#

oh right you're using doubles

#

/run

System.out.println(1d % 0);
urban needleBOT
#

Here is your java(15.0.2) output @idle rover

NaN
idle rover
#

and you stumbled upon a combination of issues that looks like it works but actually fails horribly

torn jewel
#

but the system output is 3

idle rover
#

yeah sure

#

please stop

#

if you think you know that your program works, then why are you asking here

torn jewel
#

I don't know

#

I didn't say that you don't know

#

I simply stated what I saw

idle rover
#

you keep denying what im stating

idle rover
#

you only saw the output

#
int n = input.nextInt();
System.out.println(1);
```this program finds the factorial of `n`, i tested it with `0` and `1`
torn jewel
#

Yea

#

I found the solution

#

I just had to put || instead of &&

idle rover
#

there's not the solution, again, you have multiple issues

idle rover
torn jewel
#

I just wanted to see why %0 worked and %1 didn't and I got my answer length%1 is already = because I defined length = -1

idle rover
#

look man if you're here to ask for help and then promptly ignore and deny and argue against everything the helpers try to tell you, this isn't the place for it

idle rover
torn jewel
#

I asked 2 questions you gave me the answer to the first one and I thank you for that

tall heathBOT
torn jewel
#

no

idle rover
#

you have

#

aaaand you're doing it again

torn jewel
idle rover
#

aight you have fun in your echo chamber

torn jewel
#

I accepted what you said by saying ok

#

I just wanted to know why when I placed %0 it kinda worked

idle rover
#

again, it doesn't

torn jewel
#

And I got my answer %0 is NaN so that means it's !(%0==0), and when I placed !(%1==0) it didn't work because -1%1==0 so the while didn't work

idle rover
#

% 1 is useless anyways, you always replace shit to be integers

#

completely invalidating the parseDouble you use

idle rover
torn jewel
idle rover
#

there's no logic

#

you discovered floating-point division

#

and you again did not find the solution

#

fuck this im not paid to argue with arrogance

torn jewel
#

I didn't display arrogance

#

I didn't say that you are wrong

#

simply that I've seen another issue

idle rover
#

you did lmao

#

stfu

torn jewel
#

I even thanked you with that previous one

idle rover
#

doesn't make you any better

torn jewel
#

But what I said was of a different nature

#

Even if I did your solution it still wouldn't work

idle rover
#

lmao no

torn jewel
#

Because instead of puting ||

#

I placed &&

idle rover
#

my solution is to rewrite it because your code is a mess

#

that is not a solution

#

see what i mean about arrogance?

#

ive told you this twice already

torn jewel
#

That I said that I had 2 problems

#

and once you said to use parseint hasnextint and nextint

#

I said that it's ok

#

then I just simply asked why %0 worked

idle rover
#

and i said that it didn't, and i showed why. and here you are still saying that % 0 worked

torn jewel
#

I said my question

#

I understood now why it worked but didn't at the same time

#

ok man I don't waant to argue anymore

#

thanks again for the help

tall heathBOT
# torn jewel thanks again for the help

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.

torn jewel
#

have a nice day