2 Samuel 24:10 David was conscience-stricken after he had counted the fighting men, and he said to the Lord, ‘I have sinned greatly in what I have done. Now, Lord, I beg you, take away the guilt of your servant. I have done a very foolish thing.’
There were many times when King David did things his own way because he was headstrong or lusted after something…
But, each time, after a word from the prophets, he came to God and asked for forgiveness from his ways.
Each time, God forgave him. God is faithful to forgive when we come and admit to our sins.