What's wrong with this code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What's wrong with this code?

import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner ask = new Scanner(System.in); String password = ask.nextLine(); String[] numbers={"1","2","3","4","5","6","7","8","9","0"}; String[] symbols={":","&","!","_","?","+","=","#","

quot;,"@","*","%","<"}; String result = ""; for (int x = 0; x < 10; x++){ if (password.contains(numbers[x])){ result += numbers[x]; } } String result_2 = ""; for (int y = 0; y > 14; y++){ if (password.contains(symbols[y])){ result_2 += symbols[y]; } } if (password.length() >=7 && result.length() >=2 && result_2.length() >= 2){ System.out.println("Strong"); } else { System.out.println("Weak"); } } } It doesn't count duplicate occurrence of the numbers and symbols don't know why.

2nd Oct 2020, 4:55 PM
Divine Darkey
Divine Darkey - avatar
6 Answers
+ 2
So I know .contains() iterates through your whole string and returns true or false (1 or 0) and I see your code runs both of the if statements for symbols and numbers but doesn’t add duplicate characters to result. You could try to make the result strings Integers for a count instead of adding characters to a string.
2nd Oct 2020, 6:16 PM
Roderick Davis
Roderick Davis - avatar
+ 2
also the 2nd for loop had “y > 14” where it should be “y < 13”
2nd Oct 2020, 6:23 PM
Roderick Davis
Roderick Davis - avatar
+ 2
Roderick Davis I'll try that. Thanks
2nd Oct 2020, 6:34 PM
Divine Darkey
Divine Darkey - avatar
+ 1
https://code.sololearn.com/cohCpuq82J8U/?ref=app check mine out while I try to figure yours out 🤔.
2nd Oct 2020, 5:35 PM
Roderick Davis
Roderick Davis - avatar
+ 1
and nice pic
2nd Oct 2020, 5:35 PM
Roderick Davis
Roderick Davis - avatar
2nd Oct 2020, 5:39 PM
Divine Darkey
Divine Darkey - avatar