On the right side shows a program we have a basically completed, reads a character string, called a call str_len
function to calculate the length of this string, and outputs.
Smart you should have discovered, the called str_len
function is not complete, without modifying the function prototype, complete str_len
function, we realize the functions described above it.
Sample input
abcdefg
Sample Output
7
c ++ example
#include <iostream>
using namespace std;
Int Str_len (char * Str);
int main(){
char *str = new char[100];
cin>>str;
cout<<str_len(str);
delete str;
return 0;
}
IAVA example
import java.util.*;
public class Main{
public static void main(String args[]){
Scanner input = new Scanner(System.in);
String str = input.nextLine();
System.out.println(str_len(str));
}
static int str_len(String str)
{
//请在这里完成代码
}
}
1 #include <iostream> 2 using namespace std; 3 4 int str_len(char *str); 5 6 int main(){ 7 char *str = new char[100]; 8 cin>>str; 9 cout<<str_len(str); 10 delete str; 11 return 0; 12 } 13 14 int str_len(char *str){ 15 //Please complete your function here 16 int I = 0 ; . 17 for (; STR [I] = NULL;! I ++ ) 18 is { . 19 } 20 is return I; 21 is }
import java.util.*; public class Main{ public static void main(String args[]){ Scanner input = new Scanner(System.in); String str = input.nextLine(); System.out.println(str_len(str)); } static int str_len(String str) { //请在这里完成代码 return str.length(); } }