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...)

Similar Messages

  • 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.

  • 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.

  • System.out.println() problem

    When I use operator + for concatenate the following Strings
    md.getDriverName() + md.getDriverVersion()
    as follow in a try block:
    try {
    con = DriverManager.getConnection(sourceURL,user,pass);
    md = con.getMetaData();
    System.out.println(md.getDriverName().+md.getDriverVersion());
    when I have tried run java -cp postgresql.jar errors message appers :
    Exception in thread "main" java.lang.NoClassDefFoundError: while resolving class: conx
    at java.lang.VMClassLoader.transformException(java.lang.Class, java.lang.Throwable) (/usr/lib/libgcj.so.6.0.0)
    at java.lang.VMClassLoader.resolveClass(java.lang.Class) (/usr/lib/libgcj.so.6.0.0)
    at java.lang.Class.initializeClass() (/usr/lib/libgcj.so.6.0.0)
    at java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (/usr/lib/libgcj.so.6.0.0)
    at gnu.java.lang.MainThread.run() (/usr/lib/libgcj.so.6.0.0)
    Caused by: java.lang.ClassNotFoundException: java.lang.StringBuilder not found in gnu.gcj.runtime.SystemClassLoader{urls=[file:postgresql.jar,file:./], parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}
    at java.net.URLClassLoader.findClass(java.lang.String) (/usr/lib/libgcj.so.6.0.0)
    at java.lang.ClassLoader.loadClass(java.lang.String, boolean) (/usr/lib/libgcj.so.6.0.0)
    at java.lang.ClassLoader.loadClass(java.lang.String) (/usr/lib/libgcj.so.6.0.0)
    at java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (/usr/lib/libgcj.so.6.0.0)
    But when I have used netBeans IDE v 4.0 it works fine.
    Might somebody help me for solve it.

    Caused by: java.lang.ClassNotFoundException: java.lang.StringBuilder not found in
    gnu.gcj.runtime.SystemClassLoader{urls=[file:postgresql.jar,file:./],
    As I noted in your other post, your computer is configured to use gnu.gcj, not Sun's Java - and it appears that gcj doesn't have the StringBuilder class; it was added to Sun Java in Java 5.

  • Beginner XCode/Java Question - printf problem

    Hello,
    I have just started playing around with XCode and Java. I entered the statement:
    System.out.printf("%s\n%s\n", "Welcome to", "Java Programming!");
    into the default working java project (File -> New Project -> Java Tool) and Im getting the error "cannot find symbol" after I compiled it. I do not believe this is a syntax error since it was copied straight from a textbook. So, my questions are:
    1. What "symbol" is Xcode refering to?
    2. Does Xcode coem with the latest version of Java?
    3. How can I check the Java version?
    4. Is there a library that needs to be imported to get it working?
    Thanks in advance!

    Hi Arcus
    I think you might have to change some of the Xcode settings to force it to use Java 1.5. Try this:
    - From the menu, select: Project > Edit Active Target 'Your Program Name'
    - From the popup window, select Settings > Simple View > Java Compiler Settings.
    - Set Target VM Version and Source Version to 1.5
    - Dismiss the window by clicking on the red dot at the top left corner.
    Best wishes
    Bob

  • Problem with national characters calling System.out.print(...)

    I need to develop an application printing spanish characters like "�" (ce trencada) "�", "�", etc.
    The problem is when I type
    System.out.print("�")in my application, I get "plus-minus" symbol while executing it.
    Anyone can help me, please?
    Thank you in advance.

    check the list of fonts available. You can use the following code for the purpose.
      public static void main(String args[])
            String fonts[] = getFontNames();
            for(int i = 0; i < fonts.length; i++)
                System.out.println(fonts);
    public static String[] getFontNames()
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    return ge.getAvailableFontFamilyNames();

  • System.out Problem in Java Plug-in

    I have the following problem, anyone can help me?
    I have an application( Frame ) needed to be embedded in applet. The applecation has a lot of information output to console( by System.out ). When I embeded it into applet, these information will be output to Java Plug-in Console. In the beginning, there is no problem. But when the applet runs enough time, the output will be more and more, and the speed of the applet( in fact, the browser ) runs slower and slower.
    I don't want to modify my application at all( it is impossible ). I wonder there is any good suggestion to this problem, I guess, maybe there is an interface to make the Java Plug-in clear its console buffer periodically.
    Thanks in advance.

    There is a good reason for this.... the console in the java plug-in is essentially a JTextArea... and continually adding text to it via System.out.println or the like will make it slower the longer it runs..... periodically clearing the console would be the only solution without modifying the code......
    If you still need all that information you could redirect System.out to your own PrintStream and then instead of writing to the console little by little, you could save the original System.out (using something like:
    PrintStream origSysOut=System.out;
    ) and then later on in your app reset System.out=myPrintStream or something.... then just write the myPrintStream data to origSysOut every now and then or something....
    if you want a better example of this I've got a log facility class that I built based on this principal... it's also and easy way to capture stack traces into log files... and since you're just redirecting System.out or err it's easy to turn off the log file to use for debugging.... ok that's enough of a rant :)

  • J2me sdk 3.0  problems in System.out.print

    Hi
    I can not use println to print Chinese .
    First I just use System.out.print("test") to print some debug information , and I surprised to find it print nothing.
    Then I try System.out.println("test") and it worked well. But there still problem when print Chinese,
    like System.out.println("&#27979;&#35797;") and it just print a mistake string as "??" !
    Can some tell me how to solved it, thanks .

    Note: This thread was originally posted in the [Sun Java Wireless Toolkit|http://forums.sun.com/forum.jspa?forumID=82] forum, but moved to this forum for closer topic alignment.

  • System.out.println and Network Adapter problem

    Hello,
    I am encountering a 2 strange problems. I have 2 oracle application server instances, one dev and one production.
    The first problem is when I type System.out.println in the JSP's i am able to see the output in both \opmn\logs\oc4jinstance. But the System.out.println in the java classes or bean show up only in development logs but not in production box.
    Is there a setting I am missing here?
    The second problem is on our development machine the application works fine, but as soon as we deploy the application on production I encounter:
    could not open new connection: Io exception: The Network Adapter could not establish the connection
    I have a class called DBUtils, which uses a 3rd party library to get connections from the connection pool as below. Using JSP I call the getConnection(). On my dev Oracle Application Server Instance it works fine, but on production I get the error. Can it be there is a setting that I am missing on the production box?
    When I use a JSP and connect to the database without using the DBUtil class. I can connect to the database fine. Also using the DBUtil class with production oracle IP address on the development machine lets me connect with no problem, but production machine does not let me.
    public class DBUtils {
    static ConnectionPoolBean pool;
    static {
    System.out.println("DBUtils() - before connection pool bean");
    pool = new ConnectionPoolBean();
    pool.setDriverClassName("oracle.jdbc.driver.OracleDriver");
    pool.setdbURL("jdbc:oracle:thin:@IPADDRESS:PORT:SID");
    pool.setUser("USERNAME");
    pool.setPassword("PASSWORD");
    pool.setInitialConnections(1);
    pool.setIncrement(1);
    pool.setSoftMaxConnections(40);
    public static Connection getConnection() throws SQLException {
    System.out.println("Getting Oracle Connection");
    return pool.getConnection();
    public static void returnConnection(Connection conn) throws SQLException {
    System.out.println("Returning Connection");
    pool.returnConnection(conn);
    Thanks for your help in advance.

    Hi
    System.out.println is a method of PrintStream in IO which is used to print the output on console in java progs.Here in jsp ,the o/p is printed on server's console window.But out.println is totally different as, out is implicit object derived from JspWriter and is used sly to PrinWriter 's object is used in servlets.It's work is to write upon Browser.
    System.out.println() is normally used in jsp for debugging purposes only.
    Ashish

  • Problems with System.out.println()

    I tried writing a simple 'Hello world'-program:
    public class Test{
         public static void main(String[] args){
              System.out.println("Hello World!");
         }//main()
    }//Test
    But the text wouldn't appear in the DOS-window. The only text that showed up was the standard 'Press any key to close the window'. The program compiled without any problems, but didn't work when I tried to run it.
    Does anyone have any idea what's wrong?

    Are u sure , the main() class part is donecorrectly.
    Becuse program will compile but not run without a
    main() class.what do you mean by main() class???First of all main() is a method, not a class. The main() method the JRE recognizes and runs is the:
    public static void main(String[] params)
    If you don�t have exaclty those modifiers and receive an array of Strings parameter it will send you an runtime exception.
    Your code compiles and runs fine, the problem isn�t really System.out.print() it is something with your configuration.
    I have to rename the class to TestF. Here is the running:
    C:\cJava>javac TestF.java
    C:\cJava>java TestF
    Hello World!

  • [Solved] Move system out of LVM DBus problems

    Hi,
    Earlier was using LVM and Arch age on Vol0/archlinux, today I moved the system out of LVM, then system now is on sda1, for move I do this (I can't remember the correct order but I thinks that's it):
    1. copied system using "rsync -ah --progress" ignoring sys,dev,run,mnt,proc
    2. configured /etc/fstab accordly:
    /dev/sda1 / btrfs rw,relatime,space_cache,compress=lzo 0 1
    3. from a chroot installed grub (no error reported), i.e.:
    grub-install --recheck /dev/sda
    4. booted in the system
    all are working well, except some services can't start at boot: dnsmasq and after login in console systemd-logind fail to start at first try (automatically) after it start normally and is working.
    another thing is that LightDM won't start, the complete output:
    [+0.00s] DEBUG: Logging to /var/log/lightdm/lightdm.log
    [+0.00s] DEBUG: Starting Light Display Manager 1.6.0, UID=0 PID=3230
    [+0.00s] DEBUG: Loaded configuration from /etc/lightdm/lightdm.conf
    [+0.00s] DEBUG: Using D-Bus name org.freedesktop.DisplayManager
    [+0.00s] DEBUG: Using Xephyr for X servers
    [+0.00s] DEBUG: Registered seat module xlocal
    [+0.00s] DEBUG: Registered seat module xremote
    [+0.01s] DEBUG: Adding default seat
    [+0.01s] DEBUG: Starting seat
    [+0.01s] DEBUG: Starting new display for greeter
    [+0.01s] DEBUG: Starting local X display
    [+0.01s] DEBUG: Could not run plymouth --ping: Failed to execute child process "plymouth" (No such file or directory)
    [+0.01s] DEBUG: Using VT 7
    [+0.01s] DEBUG: Logging to /var/log/lightdm/x-2.log
    [+0.01s] DEBUG: Can't launch X server Xephyr, not found in path
    [+0.01s] DEBUG: X server stopped
    [+0.01s] DEBUG: Releasing VT 7
    [+0.01s] DEBUG: Display server stopped
    [+0.01s] DEBUG: Stopping display
    [+0.01s] DEBUG: Stopping seat, failed to start a display
    [+0.01s] DEBUG: Stopping seat
    [+0.01s] DEBUG: Seat stopped
    Failed to get D-Bus connection
    tried:
    1. re-installing lightdm
    2. regenerating initramfs
    3. removing and re-installing dbus and systemd (i.e.: pacman -Rnsdd systemd dbus; pacman -S systemd dbus)
    nothing of these things solves, So I think that it isn't a LightDM issue.
    dbus-monitor looks correct!
    Last edited by hotvic (2013-07-26 03:06:54)

    Is X server Xephyr in your path?
    By the way, you would be better advised to use the rsync flags mentioned in the wiki page for full system backup with rsync to make sure that you do not lose information. -a will get most stuff but not everything. For example, ping may not work and I think you will lose ACLs as well as capabilities. I doubt this is why it can't find the X server, though.

  • Is there a way to make system.out.println() scroll down as it goes?

    I am writing a program where I want to be able to read what's printed out in the console of my IDE through System.out.println() as the program runs/after the program runs. However, right now I run the program, the message prints out, and then when I go to read it the scroll bar is all the way up so I can see only the top of the print-out (the first thing printed out). Is there any way I can get the console to scroll along with the text, kind of like floating boxes you see on various websites for various reasons? In other words, can I get it so that when I look in the console at any given moment of the program running, I am looking at the newest text printed out (the text at the bottom of the "page")? Thank you!

    That would be an IDE problem and not a Java one. You could redirect output into a text file so you can read at your leisure and scroll up and down as much as you like.

  • 32-bit JDK 7 System.out.println not working in IDE

    Hi folks,
    I have a 64-bit Windows 7 OS.
    Due to 3rd party library/jar dependencies, i had to install the 32-bit Java JDK 1.7 and Eclipse IDE.
    I also installed NetBeans.
    So i have a 64-bit OS and am running 32-bit Java JDK/JRE & IDEs.
    The problem I am having is that my program's System.out.println("...") statements are not outputting strings to either IDE debug console.
    Executing the compiled program from a command line/prompt produces the expected string output.
    The basic "Hello, World" program is enough to cause this behaviour to start occurring.
    I have not manually / intentionally changed any IDE-specific Debug Console or Windows environment settings.
    One caveat: This same environment has worked successfully in the past ?! Yes, this is one of those "..it worked last week & yesterday and today it isn't and i swear i didn't do anything..." issue.
    Thoughts ?

    Thanks for the reply.
    The 64-bit versions of Java & Eclipse were installed first.
    When i discovered I had to use the 32-bit versions, i un-installed the 64-bit ones & installed the 32-bits.
    Even after that initial un-install 64-bit/install 32-bit process, it was working.
    I have also been installing the Windows 7 64-bit OS updates when i am informed of them.
    I'm not sure if any of these would affect how the Eclipse / NetBeans IDEs behave.
    Behaviour has been inconsistent.
    Initially it was always working.
    But over the past several days, it has been working less and less.
    I don't have any large data structures.
    This isn't a large complicated program, couple hundred lines, so i highly doubt that i'm doing anything to the resources, but something has changed.
    The main project I am working on takes command line parameters, does some initial processing, produces output using System.out.printlns [SOP] then depending on the parameters, branches into 2 different processing paths, let's call them A & B. Each of these processing paths also use SOPs. When i run the program in the IDE going thru path A, sometimes the initial SOP statements will work and the SOP statements specific to path A will also work. If i immediately change the parameters to go thru path B & re-run it, not even the initial SOP statements before the branching decision work.
    I've tried doing System.flush()s too - no affect.
    I haven't tried the re-direction option to a file option you mentioned yet.
    It always works from a command prompt - that is telling me that the Java SOPs are working properly, correct ?
    Inside an Eclipse or NetBeans IDE, SOP output to the debug console is inconsistent.
    Running from a command prompt, the SOPs always work.
    It'd help to know if this an IDE issue, a Java issue, a Windows 7 issue so i can narrow down where to try and correct the situation.
    I have a Windows XP VM set up, i'll try running the program there and see if there's a difference.
    Thanks for your reply.

Maybe you are looking for