System.out.printf(); Why is it wrong?

I use Eclipse write java program.
In Linux+jdk1.6 System.out.{color:#ff0000}printf{color}("%8d",45); is right!
But {color:#0000ff}in windows+jdk1.6 , it is wrong! {color}
And it show that: {color:#0000ff}The method printf( String ,object[] ) in the type printStream is not applicable for the arguments ( String,int ){color}
Why is it wrong ? what can I do ?
Help me . Thanks!

You may have Java 1.6 but Eclipse is probably using an earlier version. Check your settings that you are using the correct version to compile with.

Similar Messages

  • System.out.printf problem

    I keep getting an error message when I type in
    System.out.printf(celsius / 5 = (fahrenheit - 32 ) / 9);
    the error keeps pointing at the first /, stating that its an unexpected type?
    How do i fix this?

    RizwanMportal wrote:
    There is System.out.print()
    and
    System.out.println()
    Do not try printf .... I think you are still in C...Since System.out is a PrintStream object, and since PrintStream has a printf method, which is wrong, the API or you Rizwan?
    see:
    http://java.sun.com/javase/6/docs/api/java/io/PrintStream.html#printf(java.lang.String,%20java.lang.Object...)

  • Cannot  resolve symbol - attempt to use System.out.printf

    Hi All,
    I adapted a HelloWorld program to use
    System.out.printf instead of System.out.println (just for a test)
    The println comand compiles fine with no errors, but for some reason the printf generates compile time error. Please let me know what am doing wrong.
    Below is the error:
    d:\j2sdk1.4.1_05\bin>javac HelloWorld.java
    HelloWorld.java:6: cannot resolve symbol
    symbol : method Printf (java.lang.String,java.lang.String)
    location: class java.io.PrintStream
    System.out.printf("%s","Hello, world!");
    ^
    1 error
    code:
    public class HelloWorld {
    public static void main (String[] args) {
    System.out.printf("%s","Hello, world!");
    }

    If you check the documentation you can see this method was added in version 1.5
    http://java.sun.com/j2se/1.5.0/docs/api/java/io/PrintStream.html#printf(java.util.Locale,%20java.lang.String,%20java.lang.Object...)
    BTW: I suggest you use a current version of java, either 1.4.2_09 or 1.5.0_04

  • System.out.printf vs System.out.println

    Hello!
    I would like to know which is faster: printf or println.
    eg:
    System.out.println("Hello " + "World");
    System.out.printf("Hello %s", "World");
    I think that println is faster, because it doesn't have to look for format parameters and then the arguments. But of course, there're sometimes that you need to use printf (System.out.printf("Wage %.2f", wage));
    Well...I just asking it, because How To Program uses it a lot, maybe it's only teaching purpose.

    Encephalopathic wrote:
    Sounds like a micro-optimization question to me where the answer is either mu or is very close to mu. IMHO, it's much better to ask which code is more understandable to me and to others helping me since that's more of a rate-limiting step in code development.Agreed. Printing to the console is not something where you need to measure performance (unless you're trying to gauge whether or not printing to the console is going to slow you down, in which case it 99.9% of the time will).

  • System.out.printf

    Hi all.
    Just a question query.
    I've just been taught the uses of the printf method in Java, but I'm still a little confused as to how it works.
    E.g.,
    System.out.printf("%o", 12); I know the o refers to octal, but I don't know much more than this. I don't want the answer (output), to this, but just a few steps on how it works to aid me in getting the answer myself. Thanks. :)
    Something so simple I know...lol. :(

    According to the API, % is a literal and the conversion does not correspond to any argument.No - The % in "%o" means "convert the argument to octal" it isn't a literal. You might be confusing this with the part of the documentation that talks about "%%" the second % in this expression is to be taken as a literal % that does not correspond to any argument. As in
    int result = 5;
    int max = 10;
    System.out.printf("%d out of %d is %.2f%%%n", result, max, (double)result / max * 100);Learn these as you need them:
    %f means a floating point number
    %d means an integer (tricky but it's d for decimal)
    %s means a string
    and
    %n means a literal newline
    %% means a literal %
    The literal characters are just printed - they don't correspond to an argument like s/d/f/o etc do.
    Well basically the steps you used in order to get from 12 to 99. It just doesn't seem obvious at all.99? It prints the string "14". It's just as confusing how you get from 12 to 14. That's because you don't: it's just the string that changes, the number stays the same.
    It's a dozen - the number of eggs in a carton. The ancient Romans would have used the string "XII" when buying eggs. The ancient Octalians would have asked for "14". In case you should ever need eggs in Octalia you figure out what to say as follows:
    Working from the right hand end, the "4" means 4 eggs. The "1" means the number of groups of 8 eggs.
    If you wanted a hundred eggs, you would ask for "System.out.printf("%o eggs, please.", 100);" - which is "144".
    4 eggs, plus 4 lots of 8 eggs, plus 1 lot of 8*8=64 eggs.

  • Why System.out.println not PrintStream.println ?

    Hi, just a beginner question
    I just wonder why should we use System.out.println, not PrintStream.println ?
    the field out in the System class is the instance of PrintStream class, isn't it?
    So why don't we just use the PrintStream class directly?
    Thanks..
    Edited by: riff_almighty on Oct 27, 2007 3:27 AM

    According to the api:
    A PrintStream adds functionality to another output stream, namely the ability to print representations of various data values conveniently. Two other features are provided as well. Unlike other output streams, a PrintStream never throws an IOException; instead, exceptional situations merely set an internal flag that can be tested via the checkError method. Optionally, a PrintStream can be created so as to flush automatically; this means that the flush method is automatically invoked after a byte array is written, one of the println methods is invoked, or a newline character or byte ('\n') is written.
    So there is nowhere mentioned about the PrintStream associated with the user console. System.out is the one instance of PrintStream which is associated with the console...
    Also println() is not a static method and cant be called upon the class...
    Edited by: VijayBabu on Oct 27, 2007 12:51 AM

  • Why System.out.println() is ok but System.out.print(); ?

    why System.out.println() is ok but System.out.print();?
    if i leave empty between parantheses in print .compiler gives error but println() doesnt?

    gimbal2 wrote:
    Think about it for a moment. What would System.out.print() do without any parameters? What CAN it do?That's easy: print() COULD behave like println() without writing a newline at the end ;)
    But I agree with Kayaman and Ram: javadoc is very nice, you simply have to read it.

  • Why we use logger instead of System.out.println for debugging?

    Hi,
    why we use logger instead of System.out.println for debugging?
    Regard
    Sankar

    Ya Basha,
    good question....
    You can use the idoc method to transfer the data when you are having an interface between the sap system and the legacy system......
    All the times BDC is not preferable like take the case you developed on upload program with bdc after some days your company thought to go for upgrade the sap vesion from lower version to upper version... in that upgraded version the application may change like sequence of fields or screens at that time you previous bdc program will not work here so u have to develop a new program and and you have to take the things into consideration again...
    where as if you use bapi or idoc method it will support the upgradations...
    in the case of bdc you have to take the data into flat files.... and then upload it to sap system after all the validations done some times the data which is in the flat file is confidential so there is no security if u take such data in flat file any user can chang the data even though if u maintain the data in application server super user can change the data
    where is idoc is fully secured... you can easily establich the interface between the systems and once it is done you can transfer the data with full security because idoc r generated by a program... so there is no manual interaction.....
    I think i gave some useful answer to you
    ~~Guduri

  • Why doesn't System.out.println work for Palm?

    In my Java code,
    how come I don't see any output on my screen (Palm Vx) when I try this?
    System.out.println("Hello World");
    Where is the output really going to???

    Hi,
    On POSE (Palm OS emulator), the System.out.println() method output is a file called STDOUT.txt, filed in some directory of the emulator.
    On the eal device, I think theres no output for system.out.println().
    Ricardo

  • Cannot Resolve Symbol - System.out

    Hi,
    I have already read about the same problem, which I will discribe soon and played around with my path variables but still I don't make positiv progress :(((
    Ok, here is my problem. Maybe I start with the code:
    import josx.rcxcomm.*;
    import java.io.*;
    public class PCModule
         public static void main( String[] args )
              recv();
         public static void recv()
              try
                   RCXPort port = new RCXPort();
                   InputStream is = port.getInputStream();
                   while( true )
                        System.out.println( "PCC_m: " + is.read() );
              catch( IOException e )
                   System.err.println( e );
    }Problem is, that I am using leJOS for the lego mindstorms RCX brig and I don't have a clue why the compiler wont use the SDK lib. Here are the important path variables:
    CLASSPATH=.;%LEJOS_HOME%/lib/classes.jar;LEJOS_HOME%/lib/pcrcxcomm.jar
    PATH=...;C:\j2sdk1.4.2_07\bin;C:\lejos\bin
    When I compile my test program I get the error message, the neither the variable out nor the variable err can be resolved which should mean, that the compiler is using the wrong class, or am I wrong? So my guess there is something wrong with the classpath. Does anybody konw which path should I add? Or maybe it is something else. One thing is for sure, I am slowly running crazy with this problem ;)

    Avoid this type of thing:
    import josx.rcxcomm.*;Wherever possible.
    Import only the lowest level packages you required, and you should be able to avoid importing their proprietary System. Of course you could just specify the full package path when referencing core java's System class.

  • Why java gives wrong answer

    float f=40.3f;
    System.out.println(f%4);
    The answer for above must be 0.3 but java gives 0.29999924
    WHY????
    (This answer is ok for small calculations but it may give wrong answers for large calculations)

    float f=40.3f;
    System.out.println(f%4);
    The answer for above must be 0.3 but java gives
    0.29999924
    WHY????
    (This answer is ok for small calculations but it may
    give wrong answers for large calculations)Use BigDecimal with MathContext or roll your own Fraction class- this way any repeating decimal is represented exactly.
    Message was edited by:
    snic.snac

  • System.out not working on eclipse

    Greetings...
    I am no longer a newbie on Java, but I have been facing an issue lately that I have been unable to resolve myself, even though it seems to be something so silly.
    I have been using eclipse for development, and by developing a simple "Just to practice" code I have found myself unable to use System class or any of its methods at a certain point. See the code below:
    package one;
    import java.util.Scanner;
    public ClassOne {
    public static void main (String args[]){
    Scanner reader = new Scanner(System.in); /*Works just fine here*/
    int x = 0;
    System.out.println("Type in the number of objects expected"); /*Does not work at all, like if System was something I could not use at all. Not an identifier */
    Scanner readertwo = new Scanner(System.in); /*System does not work here either*/
    }Even if I rewrite the code after that, by erasing the import statement and all other System references in the code, System does not work again.
    If anybody has ever faced the same issue and knows what I am doing wrong and what I can do to fix it, I'd really be grateful.
    Thanks to all, and happy 2009.
    Santana T

    Santana_Thiago wrote:
    It works on NetBeans.
    On eclipse I get the following error:
    ERROR: JDWP Unable to get JNI 1.2 Environment, jvm->GetEnv() return code = -2+
    *JDWP exit error AGENT_ERROR_NO_JNI_ENV(183): [../../../src/share/back/util.c:820]*+
    The funniest thing is that if copy and paste the code from somewhere else into eclipse it works. What a drag!!!!
    Thank you.
    Santana TNever seen that error but it sounds to me that your Eclipse installation is screwed up!

  • System.out.println () is not working properly

    Hi, Why does this happens:
    Object temp=null;
    System.out.println ("temp is null? "+temp==null);
    just prints: true
    expected: temp is null? true
    Why does this happens????
    If I do System.out.println ("temp is null? "+(temp==null)); it works bu it should work without the pharentesis too

    MelGohan wrote:
    Hi, Why does this happens:
    Object temp=null;
    System.out.println ("temp is null? "+temp==null);
    just prints: trueThat is odd, mine prints "false".
    type Test126.java
    public class Test126 {
        public static void main(String[] args) {
            Object temp=null;
            System.out.println ("temp is null? "+temp);
            System.out.println ("temp is null? "+temp==null);
    }javac Test126.java
    java Test126
    temp is null? null
    false

  • How to capture System.out, done by another program

    Hi All,
    My application runs other application in back. How can I capture system.out.println() written by another application & display via dialog box.
    Like :execl() or execv() function in C runtime library. Where every printf() message printed to passed buffer.
    Thank you,
    Avin Patel

    You can create an InputStream from a started process. Then read all the bytes from the inputstream and write them to an outputstream (like System.out)
    Process p = Runtime.getRuntime().exec(COMMAND);
    InputStream is = p.getErrorStream();   //Or another stream
    int[] buffer = new int[128];
    while((read = is.read(buffer)) != -1){
    System.write.out(buffer, 0, read);
    }

  • JDK 1.6_07 with Windows: System.out.flush() does not work...

    I wonder if this is a known issue: Since I upgrade the jdk1.6 version to the _07 pack, text IO does not work anymore with WinXP cmd.exe window. Assuming a static import of System.out, I use:
    static void prompt()
      out.print(pr); //pr is a prompt string...
      out.flush();
    }works as usual with Unix/Linux, but with windows nothing will be written to the terminal, until I make at least one input. In that case a barrage of cached prompts appear all at once.
    Do we have a bug for it, can we work around somehow?
    Thomas

    Since this code works correctly in Java 6u10 on Windows XP
    System.out.print("This is the data");
    System.out.flush();You are apparently doing something unusual or wrong. What is "out"?
    Show a small sample program that compiles and exhibits the problem when executed.

Maybe you are looking for