Java: how to initialize String[]?

后端 未结 11 2189
渐次进展
渐次进展 2020-12-22 18:57

Error

% javac  StringTest.java 
StringTest.java:4: variable errorSoon might not have been initialized
        errorSoon[0] = \"Error, why?\"         


        
11条回答
  •  梦毁少年i
    2020-12-22 19:02

    String Declaration:

    String str;
    

    String Initialization

    String[] str=new String[3];//if we give string[2] will get Exception insted
    str[0]="Tej";
    str[1]="Good";
    str[2]="Girl";
    
    String str="SSN"; 
    

    We can get individual character in String:

    char chr=str.charAt(0);`//output will be S`
    

    If I want to to get individual character Ascii value like this:

    System.out.println((int)chr); //output:83
    

    Now i want to convert Ascii value into Charecter/Symbol.

    int n=(int)chr;
    System.out.println((char)n);//output:S
    

提交回复
热议问题