iam currently on a program that reads two integers values, with the second has to be a non-zero integer.
here is my codes so far: Does it look ok ?
PLEASE HELP !:(

public class Lab2App
{

	public static void main(String[] args)
	 {
		// Calculate 5 and 3 with relation operators.
		int num1 = 5;
		int num2 = 3;


		//Print the data to the console
		System.out.println("Input integers: 5 and 3");
		System.out.println("5+3="+num1+num2);
		System.out.println("5-3="+num1 - num2);
		System.out.println("5*3="+num1*num2);
		System.out.println("5 div 3="+num1/num2);
		System.out.println("5 mod 3="+num1 - num2);
		System.out.println("Completed");
	 }
}

is this the correct coding?

System.out.println("5-3="num1 - num2);

I'm sorry - I must have been having total brain failure!
You had that right before, what I wrote was rubbish. Sorry.
(But % IS the modulo operator)

For some reason when i try to compile it, i still get an error pointing at the operator

For some reason when i try to compile it, i still get an error pointing at the operator

In your other thread, I already told you how to correct all your mistakes. I explained much in detail and told you what to change and correct, but you INSIST in writing the same things, as if you didn't pay any attention whatsoever to what I said.
You already have the solution in your other post but you chose to ignore it.

Hi javaAddict: I hadn't realised that you were already dealing with mseck's problem. (And, once again, I apologise for my "senior moment" with the + , even worse now I've read the previous thread!).
I gonna bow out now, before I make a bigger fool of myself.

Comments
I guess thats okay considering your posts are typically very helpful :)

Wow, have you read the previouse Comments.
I 've tried the same think and was getting an error.
I have added an "+" before the subtraction. i still got the error

My Code:

public class Lab2App
{

    public static void main(String[] args)
     {
        // Calculate 5 and 3 with relation operators.
        int num1 = 5;
        int num2 = 3;


        //Print the data to the console
        System.out.println("Input integers: 5 and 3");
        System.out.println();
        System.out.println("5+3=" +num1+num2);
        System.out.println("5-3=" +num1-num2);
        System.out.println("5*3=" +num1*num2);
        System.out.println("5 div 3=" +num1/num2);
        System.out.println("5 mod 3=" +num1%num2);
        System.out.println("Completed");
     }
}

Edited 3 Years Ago by Nick Evan: Fixed formatting

System.out.println("5-3=" +num1-num2);
Doesn't work

Hi javaAddict: I hadn't realised that you were already dealing with mseck's problem. (And, once again, I apologise for my "senior moment" with the + , even worse now I've read the previous thread!).
I gonna bow out now, before I make a bigger fool of myself.

That was a different thread. But that is irrelevant. Anyone can post their opinions in any thread. It is not like that once some one posts an idea no one is allowed to continue with the help.
My point was that the OP already made the same question in another thread and got an answer.


To mseck:
It seems to me that you didn't add the parenthesis I told you in one of my answers at the other thread. What is the point in asking questions if you don't follow the answers?
Add those and I believe that the errors would be fixed.
If not post again the new code with the errors

The problem are not the same.
I tried to use the exact same code i used previously.
the compiler would not accept it the way i placed it. If you want to help !help
But stop insulting me, I am new at this and trying to get help to understand:

public class Lab2App
{

    public static void main(String[] args)
     {
        // Calculate 5 and 3 with relation operators.
        int num1 = 5;
        int num2 = 3;


        //Print the data to the console
        System.out.println("Input integers: 5 and 3");
        System.out.println();
        System.out.println("5+3=" +num1+num2);
        System.out.println("5-3=" +num1-num2);
        System.out.println("5*3=" +num1*num2);
        System.out.println("5 div 3=" +num1/num2);
        System.out.println("5 mod 3=" +num1%num2);
        System.out.println("Completed");
     }
}

Edited 3 Years Ago by Nick Evan: Fixed formatting

mseck: nobody wants to insult anyone, but it is very frustrating when people don't listen. javaAddict told you how to fix that problem earlier, and reminded you in his last post.
I know its frustrating when you get a compile error you don't understand, but don't let that get in the way of reading and thinking.

Here is the error:
Lab2App.java:15: operator -cannot be applied to java.lang.String.int
System.out.println("5-3=" +num1-num2);
1 error

I do think and read all the comments.
You guys are great help but try to understand that i am trying hard understand how to do it...... Last Post did not have a subtraction operator in the equation

Thanks anyways

The solution is explained here. The example doesn't have a '-' operator but that is the idea of learning. Don't expect anywhere to find the exact code that you will need. You will find similar code, understand how it works and apply that behaviour to your needs.
Imagine what would have happened if we have told you to read the API

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

I understand where you are coming from.
Just frustating, I haven't used the () on the previous code . that what confused me. You are lot's of help, just be a little gentle, it's my first week with java.

I have lot's of other question and do not want to burn bridges.

I understand where you are coming from.
Just frustating, I haven't used the () on the previous code . that what confused me. You are lot's of help, just be a little gentle, it's my first week with java.

I have lot's of other question and do not want to burn bridges.

In our previous posts we were simply urging you to look back at that previous post.
Also if you have anymore questions fell free to create a new thread and post them. Don't forget the code. You don't want to give the wrong impression.

This question has already been answered. Start a new discussion instead.