All of us can have bad thoughts sometimes. We live in a world where bad thoughts are everywhere. Many times we don't even want to think those bad thoughts, but they pop up into our heads. It is important to understand that God looks at our hearts and intentions. God does not judge us based on what we don't intend.
Here are some ways to overcome bad thoughts:
1. Don't agree with the bad thoughts.
If bad thoughts pop into our heads and we know they are bad, don't agree with them. Reject those thoughts immediately. Say no to them.
2. Don't be in an environment where bad thoughts could come.
This means we should not watch TV that is full of violence, sexual promiscuity, or cursing. We should avoid being in the company of people who curse a lot or who encourage others to do bad things. "Do not be deceived: 'Bad company corrupts good morals.' " (1 Corinthians 15:33).
3. Pray daily for God to help you not think bad thoughts.
If we know we have a weakness, we should ask God everyday to help us.
Ask God's forgiveness for any bad thoughts. "If we confess our sins, He is faithful and righteous to forgive us our sins and to cleanse us from all unrighteousness” (1 John 1:9).
Ask for God's help to cleanse your mind and help you not think bad thoughts. Even though this step is obvious, it is something we all need to do, because even righteous people in the Bible faced these issues and were tormented by them:
"...if He rescued righteous Lot, oppressed by the sensual conduct of unprincipled men (for by what he saw and heard that righteous man, while living among them, felt his righteous soul tormented day after day by their lawless deeds), then the Lord knows how to rescue the godly from temptation..." (2 Peter 2:7-9).
So even people of the Bible were tormented by bad thoughts and bad conduct, because we all live in a sinful world. We can't help that we live in this world. Sometimes we fall into sin ourselves. So we need to keep asking for God's help and forgiveness everyday. There is no other method but prayer and diligence.