Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By gimbal2

Thread: Printf

  1. #1
    Kev
    Kev is offline Member
    Join Date
    Apr 2014
    Posts
    3
    Rep Power
    0

    Default Printf

    Hi, I have started java programming this morning and have what I am sure, is a very silly question.

    I am getting an error on the printf line below, I do not understand why this is happening, could someone please point out my mistake! I am using eclipse.

    ***The method printf(String, Object[]) in the type PrintStream is not applicable for the arguments (String, int)***

    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    import java.util.Scanner;

    public class Addition {

    public static void main(String[] args) {

    Scanner input = new Scanner ( System.in);

    int number1;
    int number2;
    int sum = number1 + number2;

    System.out.print("Enter first Number: ");
    number1 = input.nextInt();


    System.out.print("Enter second Number: ");
    number2 = input.nextInt();



    System.out.printf("The sum of the 2 number is %d\n", sum);



    }

    }

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,354
    Rep Power
    6

    Default Re: Printf

    What version of Java is configured in your workspace? I would guess it is set to Java 1.4 or lower if you get that error, the compiler does not seem to understand variable argument lists (introduced in Java 5).
    Kev likes this.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    Kev
    Kev is offline Member
    Join Date
    Apr 2014
    Posts
    3
    Rep Power
    0

    Default Re: Printf

    Thank you very much gimbal2, I will investigate this now. Your response is much appreciated.

  4. #4
    Kev
    Kev is offline Member
    Join Date
    Apr 2014
    Posts
    3
    Rep Power
    0

    Default Re: Printf

    Quote Originally Posted by Kev View Post
    Thank you very much gimbal2, I will investigate this now. Your response is much appreciated.
    Have found the issue:

    On Eclipse: Project > Properties > Java Compiler

    Compiler compliance level was set at 1.3. I have increased this and all works fine now.

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,354
    Rep Power
    6

    Default Re: Printf

    Your project in the project view should list a "JRE system library", that is all the information you need. you can also look in the project properties under java build path.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,354
    Rep Power
    6

    Default Re: Printf

    Note: Eclipse has workspace settings that are for the entire workspace and all projects in it, and you can also set settings per project. I would check the workspace settings (window -> preferences) if I were you and just let the project settings be the "default workspace settings".
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Using printf to pad spaces
    By hamster in forum New To Java
    Replies: 2
    Last Post: 05-06-2012, 06:01 PM
  2. What are these values in printf
    By josho493 in forum New To Java
    Replies: 1
    Last Post: 04-19-2012, 06:47 AM
  3. printf VS printWriter.printf
    By Mapisto in forum New To Java
    Replies: 14
    Last Post: 01-20-2012, 01:29 PM
  4. printf
    By razzle in forum New To Java
    Replies: 4
    Last Post: 11-12-2010, 03:13 PM
  5. printf
    By Jack in forum New To Java
    Replies: 2
    Last Post: 07-04-2007, 05:31 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •