Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » New to Eclipse and java
New to Eclipse and java [message #137264] Tue, 14 February 2006 14:02 Go to next message
Eclipse UserFriend
Originally posted by: david_pop12.yahoo.com

This is the First program I tried to run Eclipse 3.1 software,
Unfortunately I could not run it.
I think, I have a problem with this (System.out.printf( "Sum is %d\n",
sum);)and also I have problem using import (java.util.Scanner;)

Plese tell me how to resolve problem. The program and out put is


// Addition program that displays the sum of two numbers

import java.util.Scanner;

public class Addition {


public static void main(String[] args) {
//main method begins execution of java application
Scanner input = new Scanner( System.in );

int number1;
int number2;
int sum;

System.out.print("Enter first integer");
number1 = input.nextInt();
System.out.print( "Inter Second Integer");

sum = number1 + number2;

System.out.printf( "Sum is %d\n", sum);


}

}


Out put is the following

Exception in thread "main" java.lang.Error: Unresolved compilation
problem:
The method printf(String, Object[]) in the type PrintStream is not
applicable for the arguments (String, int)

at Addition.main(Addition.java:24)
Re: New to Eclipse and java [message #137299 is a reply to message #137264] Tue, 14 February 2006 15:26 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: a.b.com

You are writing C not java...

try...

System.out.println("Sum is " + sum);
Re: New to Eclipse and java [message #137332 is a reply to message #137299] Tue, 14 February 2006 15:35 Go to previous messageGo to next message
Darin Swanson is currently offline Darin SwansonFriend
Messages: 2386
Registered: July 2009
Senior Member
Chris you may want to read up on Java5.0 :-)
http://java.sun.com/j2se/1.5.0/docs/api/java/io/PrintStream. html#printf(java.lang.String,
java.lang.Object...)

Darins

"Chris Gage" <a@b.com> wrote in message
news:dsssqi$jo7$1@utils.eclipse.org...
> You are writing C not java...
>
> try...
>
> System.out.println("Sum is " + sum);
>
>
Re: New to Eclipse and java [message #137422 is a reply to message #137264] Tue, 14 February 2006 17:53 Go to previous messageGo to next message
Randy D. Smith is currently offline Randy D. SmithFriend
Messages: 394
Registered: July 2009
Senior Member
After that brief diversion into bringing everyone up to speed on the
"advances" of Java 5...

Sounds like your Eclipse is not actually enabling the Java 5
capabilities. How about going Help => About Eclipse SDK => Configuration
Details, then scroll down and tell us the java.runtime.name and
java.runtime.version.

Assuming all is well there (you're actually using Java 5... I don't know
how many people I've seen install Java 5 but not actually be running
it... Eclipse doesn't "magically" know it's there... it has to be on the
path at start-up or specified on the -vm line or in the preferences), go
to Window => Preferences... => Java => Compiler and tell us what the JDK
Compliance, Compiler compliance level says (should be 5.0).

5.0 is required for Scanner and C-like printf.
--
RDS



david wrote:
> This is the First program I tried to run Eclipse 3.1 software,
> Unfortunately I could not run it.
> I think, I have a problem with this (System.out.printf( "Sum is %d\n",
> sum);)and also I have problem using import (java.util.Scanner;)
>
> Plese tell me how to resolve problem. The program and out put is
>
>
> // Addition program that displays the sum of two numbers
>
> import java.util.Scanner;
>
> public class Addition {
>
>
> public static void main(String[] args) {
> //main method begins execution of java application
> Scanner input = new Scanner( System.in );
>
> int number1;
> int number2;
> int sum;
>
> System.out.print("Enter first integer");
> number1 = input.nextInt();
> System.out.print( "Inter Second Integer");
>
> sum = number1 + number2;
>
> System.out.printf( "Sum is %d\n", sum);
>
>
> }
>
> }
>
>
> Out put is the following
>
> Exception in thread "main" java.lang.Error: Unresolved compilation
> problem: The method printf(String, Object[]) in the type PrintStream
> is not applicable for the arguments (String, int)
>
> at Addition.main(Addition.java:24)
>
>
>
Re: New to Eclipse and java [message #137640 is a reply to message #137332] Wed, 15 February 2006 17:23 Go to previous message
Eclipse UserFriend
Originally posted by: a.b.com

Very Sorry. That's the second time I have been caught out by that. I
happen to be one of those who subscribe to the heretical view that 1.4 is
good enough, and 1.5 breaks too many eggs. This may be one of them.
Previous Topic:How to uninstall a plug-in
Next Topic:Specifying runtime arguments
Goto Forum:
  


Current Time: Fri Apr 26 10:11:07 GMT 2024

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

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

Back to the top