Im just starting out with java and so I am writing some simple programs to learn the basics. I was wondering what return type to use for my takeNames method? I know it has to return a string so I use "" so that the user cant see anything.
This is one of my first programs so I think I must be doing something wrong, or maybe not wrong but my code could definitely be more efficient.
import java.util.Scanner;
public class Name{
String fName;
String lName;
String line = takeNames(fName, lName);
public String takeNames(String fName, String lName){
Scanner scanner = new Scanner(System.in);
System.out.println("Enter your first and last name");
fName = scanner.next();
lName = scanner.next();
System.out.printf("Hello %s %s", fName, lName);
return "";
}
public static void main(String [] args){
Name l = new Name();
System.out.println(l.line);
}
}
Can anyone tell me if what I am using for a return statement is acceptable? Or could someone tell me a better more efficent way to write my code?
Many thanks!
return "";is a valid statement in general, its just not what you should use here.