Im looking for the program to calculate the longest password out of five seperate words and then print out that word e.g Password1: hello Password2 : two Password3: security Password4: four Password5: default Security is the longest password as it has the most characters. How do i get the program to calculate this and then print out that word | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Im looking for the program to calculate the longest password out of five seperate words and then print out that word e.g Password1: hello Password2 : two Password3: security Password4: four Password5: default Security is the longest password as it has the most characters. How do i get the program to calculate this and then print out that word

18th Nov 2016, 4:33 PM
David
2 Answers
+ 38
use include <string.h> and the function strlen(yourString[]) returnes the value of yourString including the 0 terminator.
13th Jan 2018, 8:59 PM
Worm
Worm - avatar
0
use String arreay as String[] pass = {"hello", "two", "security", "four", "default"}; String max = pass[0]; int indx=0; for(int i = 1 ; i < pass.length ; i++) { if(pass[i].length() > max.length()) { max = pass[i]; indx=i; } } System.out.println("Longest password is: "+pass[indx]);
18th Nov 2016, 4:59 PM
Vaibhav Kharche
Vaibhav Kharche - avatar