-3

//I'd like to now why I can;t printout the return value in below java code

public class client08 {
public static void main(String[] args) {
    
    String w=test();
    System.out.println(w);**// I'd like to print out the return value here but it now work**
}
public String test() {
    String result="";
    String[] words=new String[5];
    words[0]="Amy";
    words[2]="Tom";
    words[4]="Jane";
    
    for(int i=0; i<words.length;i++) {
        if(words[i]!=null) {
            result=words[i].toUpperCase();  
        }else {
            result="null";
            }
    }
    return result;
    
}
camickr
  • 321,443
  • 19
  • 166
  • 288
  • You'll have to be more specific about the problem. Is it the one about calling non-static methods from a static context? – khelwood Aug 26 '20 at 00:28

1 Answers1

0

First of all class names should start with an upper case character. Learn and follow Java conventions.

Next:

  1. Your code doesn't compile.

  2. You can't invoke a method from your "client08" class unless you create an instance of the class or make the method static.

So the code should be:

//String w=test();
client08 client = new client08();
String w= client.test();

Or you need to make the method static:

public static String test() {

Then you would invoke the method using:

String w = client08.test();
System.out.println(w);
camickr
  • 321,443
  • 19
  • 166
  • 288