Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок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
2 ответов
+ 38
use
include <string.h>
and the function
strlen(yourString[])
returnes the value of yourString including the 0 terminator.
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]);