You appear to have tried to use the code button: this inktells you how it works. Since you are new, I have corrected the code tags, and doesn't it look better now.
The code runs on JShell. As Norm said, what went wrong when you tried to run your code?
Why are you using the two for loops with break;? I think that for loops are inappropriate control structures for waht you require. I think, indeed, you shouldn't be using loops at all.
There is no beard big enough to make me comfortable enough with my masculinity to wear pink. Tiny ad: