Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Beginner: Cannot Find Symbol

Tags:

java

I've been scouring the java textbook for hours trying to determine what I'm doing wrong. The error I'm getting back is "Cannot find symbol" on line 13, which is the line with the code:

 System.out.println("The three initials are " + 
     getInitials(Harry, Joseph, Hacker));

The instructions are commented in the code. I'm pretty sure it has to do with the names I've set up.. But I'm not sure.

public class InitialsTest {
     /**
       Gets the initials of this name
      @params first, middle, and last names
      @return a string consisting of the first character of the first, middle,
  and last name
      */

    public static void main(String[] args) {
         System.out.println("The three initials are " + 
         getInitials(Harry, Joseph, Hacker));
    }

    public static String getInitials(String one, String two, String three) {
        String initials = one.substring(0,1) + two.substring(0,1) + three.substring(0,1);
        return initials;
    }

 }
like image 990
user2214850 Avatar asked Mar 27 '13 09:03

user2214850


2 Answers

System.out.println("The three initials are " 
    + getInitials("Harry", "Joseph", "Hacker")); //Enclosed within double quotes

This is how you pass String literals.

like image 134
Rahul Avatar answered Oct 06 '22 00:10

Rahul


System.out.println("The three initials are " + 
     getInitials("Harry", "Joseph", "Hacker"));

just use the double quotes . if you would have declared them as variables in your code then double quotes are not needed ,

like image 40
Anurag-Sharma Avatar answered Oct 06 '22 00:10

Anurag-Sharma