0

I get an error on this line "System.out.println((num1/dem1)(num2/dem2)); "

The error says:

Multiple markers at this line - The left-hand side of an assignment must be a variable - Syntax error on token ")", AssignmentOperator expected after this token

package project;
import java.util.Scanner;
 public class summerproject {
 public static void main(String[] args) 
 {
 Scanner in = new Scanner( System.in );
 {
 //INPUT NUMBERS
 System.out.println("Enter Numerator 1. ");
 int num1 = in.nextInt(); 
 System.out.println("Enter Denominator 1. ");
 int dem1 = in.nextInt();
 System.out.println("Enter Numerator 2. ");
 int num2 = in.nextInt();
 System.out.println("Enter Denominator 2. ");
 int den2 = in.nextInt();
 }
 System.out.println("Press 1 to multiply");
 int mult = in.nextInt();
 if (mult == 1)
 {
 System.out.println((num1/dem1)(num2/dem2)); 
 }
 }//ARGS BRACKET 
 }//END BRACKET
Casey
3,3831 gold badge28 silver badges42 bronze badges
asked Aug 27, 2014 at 0:27
1
  • Perhaps it is expecting an operator between values. Are you sure you're not trying to do something like System.out.println((num1/dem1) + " " + (num2/dem2)); or as mattingly pointed out, * between them to multiply. Commented Aug 27, 2014 at 0:29

2 Answers 2

2

This line isn't valid:

System.out.println((num1/dem1)(num2/dem2));

(num1/dem1) and (num2/dem2) need to have an operator between them. For example, to multiply the two expressions together, use the * operator:

(num1/dem1)*(num2/dem2)

Java doesn't behave quite like mathematics, where concatenation implies multiplication. Instead, you have to explicitly multiply operands together.


In addition, you declared

int den2 = in.nextInt();

This should be

int dem2 = in.nextInt().

After adjusting braces appropriately, and making the above fixes, you should end up with:

public class summerproject {
 public static void main(String[] args) {
 Scanner in = new Scanner(System.in);
 //INPUT NUMBERS
 System.out.println("Enter Numerator 1. ");
 int num1 = in.nextInt();
 System.out.println("Enter Denominator 1. ");
 int dem1 = in.nextInt();
 System.out.println("Enter Numerator 2. ");
 int num2 = in.nextInt();
 System.out.println("Enter Denominator 2. ");
 int dem2 = in.nextInt();
 System.out.println("Press 1 to multiply");
 int mult = in.nextInt();
 if (mult == 1) {
 System.out.println((num1 / dem1) * (num2 / dem2));
 }
 }
}

An example run:

Enter Numerator 1. 
20
Enter Denominator 1. 
4
Enter Numerator 2. 
30
Enter Denominator 2. 
5
Press 1 to multiply
1
30
answered Aug 27, 2014 at 0:31
Sign up to request clarification or add additional context in comments.

10 Comments

I dont think you can put ints in println, that might be the real issue. It needs a string
Pretty sure you can. println is heavily overloaded and I use that all the time on int testing
System.out is an instance of PrintStream, which has overloaded methods for printing the primitive types and objects. See docs.oracle.com/javase/7/docs/api/java/io/PrintStream.html Thus, printing ints is just fine.
I just tested @meda claim above to double check... you can in fact print an int
he also has extra set of brackets which places his variables out of scope
|
1

You need an operator in the middle of your operations

Your code seems to indicate you want to multiply so try the code below instead...

System.out.println((num1/dem1)*(num2/dem2));
answered Aug 27, 2014 at 0:32

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.