从用户输入打印时出错

时间:2014-05-29 02:22:36

标签: java eclipse

我有一个简单的JAVA程序,我在Eclipse中编写,我用作大型程序的构建块,出于某种原因,我收到了 System.out.println的错误 即可。

提前致谢!

错误: PrintStream类型中的println(String)方法不适用于参数(String,String,String)

代码:

package UserInfo;

import java.util.*;
import java.util.Scanner.*;
import java.awt.*;
import javax.swing.*;
import java.io.*;

public class UserInfo {

    public UserInfo() {
        // TODO Auto-generated constructor stub
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        System.out.println ("This program will gather your personal information. \n\n");

        Scanner userInput = new Scanner (System.in);

        System.out.println ("Enter your first name: ");
        String firstName = userInput.nextLine();

        System.out.println ("Enter your last name: ");
        String lastName = userInput.nextLine();

        System.out.println ("Enter your street address: ");
        String addressStreet = userInput.nextLine();

        System.out.println ("Enter your city: ");
        String addressCity = userInput.nextLine();

        System.out.println ("Enter your two letter state abbreviation (ex:TN): ");
        String addressState = userInput.nextLine();

        System.out.println ("Enter your 5 digit zip code: ");
        Integer addressZip = userInput.nextInt();
/*
        System.out.printf ("Enter your phone number (ex: 1234567890): ");
        Integer addressPhone = userInput.nextInt();
*/      
        String addressQualified = (addressStreet + "\n" + addressCity + "" + addressState + ", " + addressZip + "\n");
        String nameQualified = firstName + "" + lastName + "\n";

        System.out.println ("User: ", nameQualified, "\n"); **//Error here**
        System.out.println ("Users Address: ", addressQualified, "\n"); **//Error here**
        //System.out.printf ("User Phone: ", addressPhone, "\n");

    }

}

4 个答案:

答案 0 :(得分:2)

 System.out.println ("User: " + nameQualified + "\n"); **//Error here**
 System.out.println ("Users Address: " + addressQualified + "\n"); **//Error here**

语法错误,它" +"而不是","

" +"用于连接String

""用于分隔方法的不同参数/参数。

答案 1 :(得分:0)

就像它说的那样,System.out.println没有三个String参数的方法。你可能打算这样做:

System.out.println ("User: " + nameQualified + "\n");
System.out.println ("Users Address: " + addressQualified + "\n");
//System.out.printf ("User Phone: " + addressPhone + "\n");

您知道,参数(也称为参数)在方法调用中用逗号分隔。你可以看到这就是你实际给出方法三个参数的原因。

+串联在一起,就像你想要的那样。

答案 2 :(得分:0)

System.out.println ("User: ", nameQualified, "\n"); **//Error here**

如错误所示,println只需要1个输入/ arg / param。因此将输入连接到1个字符串如下:

System.out.println ("User: " + nameQualified + "\n"); 

更多信息: http://docs.oracle.com/javase/6/docs/api/java/io/PrintStream.html#println(java.lang.String)

What's the meaning of System.out.println in Java?

答案 3 :(得分:-1)

语法错误,您需要使用+符号连接