printf不会返回String变量,只返回一个对象

时间:2014-05-21 18:28:09

标签: java object printf

我正在学习本教程,其中有多个方法是多个类,但这一行代码不起作用。这是在带有eclipse的java 8中。这是教程:http://thenewboston.org/watch.php?cat=31&number=16 system.out.printf的错误一直在说

  

PrintStream类型中的printf(String)方法不适用   对于参数(String,String)

  

方法printf(String,Object [])不适用于   arguments(String,String)

唯一的建议是将Public String getName()的返回类型更改为对象,这会导致其他错误。请帮忙!

代码如下:

import java.util.Scanner;

public class collin {
    public static void main(String [] args) {

        Scanner keyboard = new Scanner(System.in);

    collin2 collin2Object = new collin2();
    System.out.println("Enter the name of your first girlfriend here: ");

    String temp = keyboard.nextLine();
    //temp is the variable that sets the name.
    collin2Object.setName(temp);

    collin2Object.saying();

    keyboard.close();
    }
}


public class collin2 {

    private String girlName;
    public void setName(String name){
        girlName = name;
    }
    public String getName() {
        return girlName;
    }

    public void saying () {
        System.out.printf("The name of your first girlfriend was %s", getName());
    }
}

0 个答案:

没有答案