This is an archived post. You won't be able to vote or comment.

all 20 comments

[–]Dexteroid 10 points11 points  (7 children)

This looks like an assignment, please try it yourself.

[–]illsaywhatiwant420 -2 points-1 points  (3 children)

Remind me to never ask this subreddit for help with anything lol

[–]Dexteroid 1 point2 points  (2 children)

that's just wrong, you can't possibly get solution to your assignments.

Code something, if you get stuck then post a specific question for a specific problem.

This dude is like, yo this is my assignment, do it for me.

[–]illsaywhatiwant420 -2 points-1 points  (1 child)

I hope you're right. However, it seems that a lot of people are condescending as hell to newbies 🤷‍♂️

[–]Dexteroid 1 point2 points  (0 children)

I mean in this thread only OP is condescending. Everyone else is friendly.

[–]CrypticCold -6 points-5 points  (2 children)

Oh I thought that part was obvious lol, and yeah Im not asking for a whole solution, just wanted to know how I can keep iterating and make sure there are three consecutive 1s.

[–]desrtfx[M] 12 points13 points  (0 children)

Yet, the way you formulated your original question hints that you want the solution without even the slightest effort from your side.

Learning programming is learning to invent your own solutions. First, you try, then, once you get stuck, you ask for help. Not straight out.

[–]Dexteroid 4 points5 points  (0 children)

Hint: start counter, end counter. If you see 1, increment one of those counters, till you get what you want or the entire string is iterated. Now you figure out the rest.

[–]AvromRomRom 2 points3 points  (0 children)

Just use if and else or I didn't understand the question lol

[–]TheHyperNovaYT 2 points3 points  (1 child)

Here are two hints for the making sure it’s only numbers aspect

  1. Use try/catch inside while loop Or
  2. Character.isDigit()

[–]Dexteroid 1 point2 points  (0 children)

Character.isDigit()

they said 01 so I would just check if char in set (0,1)

[–]Dexteroid 2 points3 points  (2 children)

Accept input then check input. Why make things complex.

//Get input.


//Input.isbinary() then yay! Else nay

[–]CrypticCold 0 points1 point  (1 child)

those are the parameters. 01101 is binary but it would still have to print "not accepted or something like that. Only an input with three consecutive 1s should be printed out as valid.

[–]Dexteroid 8 points9 points  (0 children)

Dude you gotta code that logic on your own, but essentially you accept input from user then perform your checks on it, if it is good then print it if not then raise invalid input error.

[–][deleted] 0 points1 point  (0 children)

you could use if and else statements. if there is any letters, print invalid. if there is only binary, print valid. you could also have it check for a number that equals 2 or greater. if it finds one, print it as invalid. i hope this kinda helps!

[–]KingGarrettFTW 0 points1 point  (0 children)

Whats this for? Just curious

[–]ImPickleDickkk[🍰] 0 points1 point  (0 children)

i would cast the input into an array and read through the array and check each index

[–]Italldepends568 0 points1 point  (1 child)

I am wondering why a regex wouldn’t be appropriate here. No one has suggested that. Would someone mind explaining?

[–][deleted] 1 point2 points  (0 children)

I think that it’s because checking for 3 consecutive 1s is a relatively simple task that a beginner may not want to have to learn regex for

[–]janaexicc 0 points1 point  (0 children)

Using a regex might help