Skip to main content



      Home
Home » Newcomers » Newcomers » System.out.printf Broken?
System.out.printf Broken? [message #56194] Thu, 21 April 2005 18:51 Go to next message
Eclipse UserFriend
Originally posted by: tim.julian.hsc.utah.edu

When I run the simple code from a Deitle book such as the following:

import java.util.Scanner; // program uses Scanner

public class Product
{
public static void main( String args[] )
{
// create Scanner to obtain input from command window
Scanner input = new Scanner( System.in );

int x; // first number input by user
int y; // second number input by user
int z; // third number input by user
int result; // product of numbers

System.out.print( "Enter first integer: " ); // prompt for input
x = input.nextInt(); // read first integer

System.out.print( "Enter second integer: " ); // prompt for input
y = input.nextInt(); // read second integer

System.out.print( "Enter third integer: " ); // prompt for input
z = input.nextInt(); // read third integer

result = x * y * z; // calculate product of numbers

System.out.printf( "Product is %d\n", result );


} // end method main

} // end class Product

It says .printf is expecting an object[] and not an int!
Any ideas?
(the scanner works fine as contrasted with the new NetBeans!)
Re: System.out.printf Broken? [message #57298 is a reply to message #56194] Mon, 25 April 2005 20:05 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: Chris_Laffra.ca.ibm.com

What version of Eclipse are you running? You need at least 3.1M6

--
Chris Laffra, http://eclipsefaq.org


"Tim Julian" <tim.julian@hsc.utah.edu> wrote in message
news:2771bd5dde50f1a1760f1908933d8346$1@www.eclipse.org...
> When I run the simple code from a Deitle book such as the following:
>
> import java.util.Scanner; // program uses Scanner
>
> public class Product
> {
> public static void main( String args[] )
> {
> // create Scanner to obtain input from command window
> Scanner input = new Scanner( System.in );
>
> int x; // first number input by user
> int y; // second number input by user
> int z; // third number input by user
> int result; // product of numbers
>
> System.out.print( "Enter first integer: " ); // prompt for input
> x = input.nextInt(); // read first integer
>
> System.out.print( "Enter second integer: " ); // prompt for input
> y = input.nextInt(); // read second integer
>
> System.out.print( "Enter third integer: " ); // prompt for input
> z = input.nextInt(); // read third integer
>
> result = x * y * z; // calculate product of numbers
>
> System.out.printf( "Product is %d\n", result );
>
>
> } // end method main
>
> } // end class Product
>
> It says .printf is expecting an object[] and not an int!
> Any ideas?
> (the scanner works fine as contrasted with the new NetBeans!)
>
>
>
Re: System.out.printf Broken? [message #57627 is a reply to message #57298] Tue, 26 April 2005 09:46 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: tim.julian.hsc.utah.edu

I am running 3.0.2. Is not that the latest "safe" version?
Re: System.out.printf Broken? [message #57652 is a reply to message #57298] Tue, 26 April 2005 10:12 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: tim.julian.hsc.utah.edu

I reloaded the latest version: 3.1M6 and it still gave me the error: "the
method printf( String, Object[]) in the type PrintStream is not applicable
for the arguments (String,int). Any ideas?

int result = 1;
System.out.printf( "result= %d\n", result );

It does not get much simpler than this....
Re: System.out.printf Broken? [message #58554 is a reply to message #56194] Wed, 27 April 2005 16:55 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: john.eclipsefaq.org

Are you using a Java 1.5 VM? Make sure your JRE (Preferences > Java >
Installed JREs) is using Java 1.5. The method you are trying to use was
only introduced in this version of Java, which did not exist at the time
Eclipse 3.0 was released.
--

Tim Julian wrote:
> When I run the simple code from a Deitle book such as the following:
> import java.util.Scanner; // program uses Scanner
>
> public class Product {
> public static void main( String args[] )
> {
> // create Scanner to obtain input from command window
> Scanner input = new Scanner( System.in );
>
> int x; // first number input by user
> int y; // second number input by user
> int z; // third number input by user
> int result; // product of numbers
>
> System.out.print( "Enter first integer: " ); // prompt for input
> x = input.nextInt(); // read first integer
>
> System.out.print( "Enter second integer: " ); // prompt for input
> y = input.nextInt(); // read second integer
> System.out.print( "Enter third integer: " ); // prompt for input
> z = input.nextInt(); // read third integer
>
> result = x * y * z; // calculate product of numbers
>
> System.out.printf( "Product is %d\n", result );
>
> } // end method main
>
> } // end class Product
>
> It says .printf is expecting an object[] and not an int!
> Any ideas?
> (the scanner works fine as contrasted with the new NetBeans!)
>
>
>
Re: System.out.printf Broken? [message #58988 is a reply to message #58554] Thu, 28 April 2005 10:00 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: tim.julian.hsc.utah.edu

Yes, I have JRE 1.5 installed. If you will notice the scanner object is
part of 1.5. The scanner object works fine, it is the System.out.printf
method that does not work.
Re: System.out.printf Broken? [message #59087 is a reply to message #58988] Thu, 28 April 2005 11:36 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: wegener.cboenospam.com

Tim Julian wrote:

> Yes, I have JRE 1.5 installed. If you will notice the scanner object is
> part of 1.5. The scanner object works fine, it is the System.out.printf
> method that does not work.

You also need to have the Java Complier compliance set to 1.5.
Re: System.out.printf Broken? [message #59685 is a reply to message #59087] Fri, 29 April 2005 14:19 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: tim.julian.hsc.utah.edu

That finally fixed the problem: windows / preferences / compiler /
Compiler compliance level

Set to 5.0

It is odd that the scanner object did work correctly however....
Re: System.out.printf Broken? [message #59709 is a reply to message #59685] Fri, 29 April 2005 14:27 Go to previous message
Eclipse UserFriend
Originally posted by: wegener.cboenospam.com

Tim Julian wrote:

> That finally fixed the problem: windows / preferences / compiler /
> Compiler compliance level

> Set to 5.0

> It is odd that the scanner object did work correctly however....

It sounds like you are confusing the language specification with the
runtime library. 5.0 made changes to both. The Scanner is a new class in
the runtime library. The compiler changes necessary to convert the
System.printf arguments properly is a language change.

You can use a 1.4 compiler to compile classes that reference the 5.0
runtime libraries.
Previous Topic:HTML WYSIWYG Editor
Next Topic:Dump Question: The requested resource (/tutorial/snoop) is not available
Goto Forum:
  


Current Time: Fri Apr 25 01:22:02 EDT 2025

Powered by FUDForum. Page generated in 0.10041 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top