-1

I have a simple JAVA program that I have written in Eclipse and I am using as a building block for a larger program, for some reason, I am getting an error with the System.out.println.

Thanks in advance!

Error: The method println(String) in the type PrintStream is not applicable for the arguments (String, String, String)

Code:

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");

    }

}
Kevin Schultz
  • 886
  • 3
  • 20
  • 42
  • That is not the correct format for System.out.println(). println() accepts a String argument. You have provided three String arguments. Try doing this: System.out.println ("User: " + nameQualified + "\n"); – Edwin Torres May 29 '14 at 02:27

4 Answers4

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

Wrong syntax, it's "+" instead of ","

"+" is used for concatenation of String

"," is used to separate different arguments/parameters for methods.

Sky
  • 3,350
  • 2
  • 14
  • 12
0

Just as it says, there is no method for System.out.println with three String parameters. You probably meant to do this:

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

Just so you know, parameters (also called arguments) are separated by commas in method calls. You can see that's why you were actually giving the method three parameters.

The + concats strings together, like you intended.

Michael Yaworski
  • 13,410
  • 19
  • 69
  • 97
0
System.out.println ("User: ", nameQualified, "\n"); **//Error here**

As the error says, println takes only 1 input/arg/param. So concat the input to 1 string as follows:

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

More info here: 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?

Community
  • 1
  • 1
Bobz
  • 2,394
  • 1
  • 19
  • 20
-1

Wrong syntax, you need to concatenate using the + sign