Hello

I am new at java programming and having a hard time at this very basic coding.

How to i write a java application that inouts 3 different integers from the keyboard and prints the outpout as in the following :


Output

the 3 different integers are: 13, 27, 14.
the sum is 54.
The product is 4914
completed.

Good Morning !

Who said it was my homework?
I am trying to lean it on my own, I've tried to do it but keep on getting error.

i would appreciate, if i could get directed the right direction.


thank you

Good Morning !

Who said it was my homework?
I am trying to lean it on my own, I've tried to do it but keep on getting error.

i would appreciate, if i could get directed the right direction.


thank you

Then post your code, and don't tell me that you couldn't do this:

int sum = num1+num2+num3;
int prod = num1*num2*num3;

And if you say that you already know that, you asked:

How to i write a java application that inouts 3 different integers from the keyboard and prints the outpout as in the following :

Output

the 3 different integers are: 13, 27, 14.
the sum is 54.
The product is 4914
completed.

You don't mention anywhere where is your problem. From your question you make it sound that you want the whole thing done.

Post what you have done so far and with what are you having problems.

Edited 6 Years Ago by javaAddict: n/a

I was looking for help ! Not to get murder for not knowing how to do a very basic programming.

Thanks guys
will put my code later, when i get home

IS This Correct ?

public class Lab1App
{

	public static void main(String[] args)
	 {
		// Calculate three integers 13, 27, 14.
		int num1 = 13;
		int num2 = 27;
		int num3 = 14;
		
		//Print the data to the console
		system.out.println(" the 3 different integers are 13, 27, 14.);
		system.out.println("The sum is:      "num1 + num2 + num3);
		system.out.println("The product:     "num1 * num2 * num3);
		system.out.println("Complete.")
	 }
}

First of all use capital S:
System....

Second you do this:

system.out.println("The sum is:      "[B]+[/B]num1 + num2 + num3);

- You forgot the '+'
- Things are executed from right to left:

"The sum is: "+num1 + num2 + num3 -->
"The sum is: "+13 + 27+ 14
Meaning that first this will calculate:
"the sum is: "+13, which will create the String:
"The sum is 13".
Then this:
"The sum is 13" + 27, which will create the String:
"The sum is 1327".
Then this:
"The sum is 1327" + 14, which will create the String:
"The sum is 132714".

Whenever you "add" something with a String is turned into a String as well.


> num1=5
> num2=6

This: "A= "+num1 will return
>A= 5
This: "A= "+num1+num2 will return
>A= 56
This: "A= "+(num1+num2) will return
>A= 11

You should do this:

System.out.println("The sum is: " + (num1 + num2 + num3) );
System.out.println("The product: " + (num1 * num2 * num3) );

Or better, use the code from my first post.

Also without posting code, there was no way to help you. the only thing we could do is give you the complete code, which is unacceptable here.
Now you got the chance to learn something as well.

Also check your "" quotes at the System.out :

System.out.println(" ")

you forgot to close them at the first System.out

Edited 6 Years Ago by javaAddict: n/a

For some reason i still get error
Could it be the way i installed JDK 6.18?

Lab1App.java:14: ')' expected
System.out.println("The product: "num1*num2*num3);
^
Lab1App.java:14: illegal start of expression
System.out.println("The product: "num1*num2*num3);
^
Lab1App.java:14: ';' expected
System.out.println("The product: "num1*num2*num3);
^
Lab1App.java:14: not a statement
System.out.println("The product: "num1*num2*num3);
^
Lab1App.java:14: ';' expected
System.out.println("The product: "num1*num2*num3);
^

For some reason i still get error
Could it be the way i installed JDK 6.18?

Check your quotes.
Then post your new code, with what error messaged you get.

For future reference, first open AND close a double quote, and then start writing inside.
the same goes for opening brackets and parenthesis

Lab1App.java:14: ')' expected
System.out.println("The product: "num1*num2*num3);
^
Lab1App.java:14: illegal start of expression
System.out.println("The product: "num1*num2*num3);
^
Lab1App.java:14: ';' expected
System.out.println("The product: "num1*num2*num3);
^
Lab1App.java:14: not a statement
System.out.println("The product: "num1*num2*num3);
^
Lab1App.java:14: ';' expected
System.out.println("The product: "num1*num2*num3);
^

In my previous post, I ,mentioned that you forgot the '+' symbol and some quotes

This it the code i have after changes:

public class Lab1App
{

	public static void main(String[] args)
	 {
		// Calculate three integers 13, 27, 14.
		int num1 = 13;
		int num2 = 27;
		int num3 = 14;

		//Print the data to the console
		System.out.println("The 3 different integers are 13, 27, 14.");
		System.out.println("The sum is:      "+num1+num2+num3);
		System.out.println("The product:     "num1*num2*num3);
		System.out.println("Complete.");
	 }
}

Like I said, read the explanation I gave you at post #8
And you forgot another '+' at the line where you print the product

This article has been dead for over six months. Start a new discussion instead.