Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: What's wrong with the PRINTF statement ?

  1. #1
    Junior Member
    Join Date
    Jan 2010
    Posts
    14
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default What's wrong with the PRINTF statement ?

    Hello guys, i have been trying to play around with System.out.printf , but it says that the method is not applicable to the attributes.. i don't think i am doing anything wrong but i can't understand what's going on.. below is my code :

     
    package com.examples;
     
    import java.util.Scanner;
     
    public class Comparison {
     
    	public static void main(String[] args) {
     
    		Scanner input = new Scanner( System.in );
     
    	      int number1; 
    	      int number2; 
     
    	      System.out.print( "Enter first integer: " ); 
    	      number1 = input.nextInt();  
     
    	      System.out.print( "Enter second integer: " ); 
    	      number2 = input.nextInt();  
     
    	      if ( number1 == number2 ) 
    	         System.out.printf( "%d == %d\n", number1, number2 );
     
    	      if ( number1 != number2 )
    	         System.out.printf( "%d != %d\n", number1, number2 );
     
    	      if ( number1 < number2 )
    	         System.out.printf( "%d < %d\n", number1, number2 );
     
    	      if ( number1 > number2 )
    	         System.out.printf( "%d > %d\n", number1, number2 );
     
    	      if ( number1 <= number2 )
    	         System.out.printf( "%d <= %d\n", number1, number2 );
     
    	      if ( number1 >= number2 )
    	         System.out.printf( "%d >= %d\n", number1, number2 );
     
    	}
     
    }

    and this basic code :

     
     System.out.printf( "%s\n%s\n", 
             "Welcome to", "Java Programming!" );


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: What's wrong with the PRINTF statement ?

    Please copy the full text of the error message and paste it here. It has important info about the error.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    smartshahezad (July 7th, 2014)

  4. #3
    Junior Member
    Join Date
    Jan 2010
    Posts
    14
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default Re: What's wrong with the PRINTF statement ?

    Quote Originally Posted by Norm View Post
    Please copy the full text of the error message and paste it here. It has important info about the error.
    for the second statement :

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


    and for the class Comparison, it gives the error everywhere where i have printf :

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

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: What's wrong with the PRINTF statement ?

    What version of the JDK are you using?
    How are you compiling the source? Are you using the javac command? If not, try it to get better error messages. The error messages you posted are not very good.
    If you don't understand my answer, don't ignore it, ask a question.

  6. The Following User Says Thank You to Norm For This Useful Post:

    smartshahezad (July 7th, 2014)

  7. #5
    Junior Member
    Join Date
    Jan 2010
    Posts
    14
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default Re: What's wrong with the PRINTF statement ?

    Quote Originally Posted by Norm View Post
    What version of the JDK are you using?
    How are you compiling the source? Are you using the javac command? If not, try it to get better error messages. The error messages you posted are not very good.
    the java -version command in cmd say i have 1.8.0_05-b13

    --- Update ---

    Quote Originally Posted by Norm View Post
    What version of the JDK are you using?
    How are you compiling the source? Are you using the javac command? If not, try it to get better error messages. The error messages you posted are not very good.
    and no i am not using the javac command.. my IDE is doing it for me..

    --- Update ---

    I DID IT.. there was a problem with my JRE library.. i had to change it to JavaSE 1.7 and everything's working great now..

    Thanks as always.. really appreciate your inputs..

  8. #6
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: What's wrong with the PRINTF statement ?

    If you're using Eclipse Kepler SR2, there is a patch for Java 8 you may have to install to avoid these kind of errors. Just search 'eclipse java 8 patch'. Eclipse Luna has Java 8 support built in.

Similar Threads

  1. Help with Printf statement
    By richardman54 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 23rd, 2013, 03:28 PM
  2. something is wrong with if-statement?
    By Dixxon in forum What's Wrong With My Code?
    Replies: 22
    Last Post: November 17th, 2013, 01:44 PM
  3. what's wrong with this statement
    By ghostheadx in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 30th, 2013, 01:18 AM
  4. [SOLVED] What's Wrong With My Code: If Statement.
    By Java Programmer in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 9th, 2012, 08:31 PM
  5. What is wrong with my if/else statement?
    By CSUTD in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 24th, 2011, 02:34 PM