False logic it looks like. Your second for loop has k=i, i=1. So k has to be bigger than or equal to 2. So it is doing what you have coded. If you want 3,4,3, there is no math statement that is going to go from 3 to 4 to 3. However, you might be able to set an if statement that says if it is bigger than 4, print 4. I program in python, but this is java I think. I think this is the wrong forum for this question though. Try stack overflow. That is a programming community. Also, try explaining more about what you're trying to do or else no one will respond to you over in stack overflow.