import java.util.Scanner;

class Calculator{
   public static void main  (String [] args) {
       Scanner suslady = new Scanner(System.in);

       int fnum, snum, remander, answer;
       char operation;
       System.out.print ("Enter 1st # ");
       fnum = suslady.nextInt();
       operation = suslady.nextChar();
       System.out.print ("Enter 2nd # ");
       snum  = suslady.nextInt();


   if(operation == '+') {
           answer = fnum + snum;
           System.out.print ("Answer: ");
           System.out.println (answer);
       } 
   if(operation == '-') {
           answer = fnum - snum;
           System.out.print ("Answer: ");
           System.out.println (answer);
       }
   if(operation == *') {
           answer = fnum * snum;
           System.out.print ("Answer: ");
           System.out.println (answer);
       }
   if(operation == '/') {
       remander = fnum % snum;
       answer = fnum / snum;
       System.out.print ("Answer: ");
       System.out.println (answer);
       System.out.print ("Remander: ");
       System.out.println (remander);
   }
   }
}

When I run it it says

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    Syntax error on token(s), misplaced construct(s)

at Calculator.main(Calculator.java:4)

ps. I use eclipse

Edited 3 Years Ago by Nick Evan: Fixed formatting

Can you compile the program and get a compilation error? Don't try to execute it.

Which line is line 4?

Can you compile the program and get a compilation error? Don't try to execute it.

Which line is line 4?

line 4 is public static void main (String [] args) {

import java.util.Scanner;

class Calculator {
	public static void main (String[] args) {
		
		Scanner suslady = new Scanner(System.in);
		int fnum =0, snum=0, remander=0, answer=0;
		char operation ;
		System.out.print ("Enter 1st # ");
		fnum = suslady.nextInt();
		operation =suslady.nextChar();
		System.out.print ("Enter 2nd # ");
		snum = suslady.nextInt();


		if(operation == '+') {
			answer = fnum + snum;
			System.out.print ("Answer: ");
			System.out.println (answer);
		} else
		if(operation == '-') {
			answer = fnum - snum;
			System.out.print ("Answer: ");
			System.out.println (answer);
		}else
		if(operation == '*') {
				answer = fnum * snum;
		System.out.print ("Answer: ");
		System.out.println (answer);
	}
	if(operation == '/') {
		remander = fnum % snum;
		answer = fnum / snum;
		System.out.print ("Answer: ");
		System.out.println (answer);
		System.out.print ("Remander: ");
		System.out.println (remander);
	}
}
}

I was able to fix it, your error was at this

if(operation == *')

the only error now is when you get the input, since there is no such method as nextChar(); :)

import java.util.Scanner;

class Calculator {
	public static void main (String[] args) {
		
		Scanner suslady = new Scanner(System.in);
		int fnum =0, snum=0, remander=0, answer=0;
		char operation ;
		System.out.print ("Enter 1st # ");
		fnum = suslady.nextInt();
		operation =suslady.nextChar();
		System.out.print ("Enter 2nd # ");
		snum = suslady.nextInt();


		if(operation == '+') {
			answer = fnum + snum;
			System.out.print ("Answer: ");
			System.out.println (answer);
		} else
		if(operation == '-') {
			answer = fnum - snum;
			System.out.print ("Answer: ");
			System.out.println (answer);
		}else
		if(operation == '*') {
				answer = fnum * snum;
		System.out.print ("Answer: ");
		System.out.println (answer);
	}
	if(operation == '/') {
		remander = fnum % snum;
		answer = fnum / snum;
		System.out.print ("Answer: ");
		System.out.println (answer);
		System.out.print ("Remander: ");
		System.out.println (remander);
	}
}
}

I was able to fix it, your error was at this

if(operation == *')

the only error now is when you get the input, since there is no such method as nextChar(); :)

Thanks alot! :) but now when i run it it says Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method nextChar() is undefined for the type Scanner

at Calculator.main(Calculator.java:11)

import java.util.Scanner;

class Calculator{
public static void main (String [] args)
{
Scanner suslady = new Scanner(System.in);

int remander, answer;
System.out.print("Enter 1st # ");
String inp1 = suslady.nextLine();
int fnum=Integer.parseInt(inp1);
System.out.print("Enter Operation");
String operat = suslady.nextLine();
System.out.print ("Enter 2nd # ");
String sm = suslady.nextLine();
int snum=Integer.parseInt(sm);

if(operat.equals("+"))
{
answer = fnum + snum;
System.out.print ("Answer: ");
System.out.println (answer);
}

if(operat.equals("-"))
{
answer = fnum - snum;
System.out.print ("Answer: ");
System.out.println (answer);
}

if(operat.equals("*"))
{
answer = fnum * snum;
System.out.print ("Answer: ");
System.out.println (answer);
}

if(operat.equals("/"))
{
remander = fnum % snum;
answer = fnum / snum;
System.out.print ("Answer: ");
System.out.println (answer);
System.out.print ("Remander: ");
System.out.println (remander);
}
}
}

Use this.It's working properly.

Thanks alot! :) but now when i run it it says Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method nextChar() is undefined for the type Scanner

at Calculator.main(Calculator.java:11)

are you not paying attention what i just posted? I told you there is no such thing as nextChar() in the Scanner API

import java.util.Scanner;

class Calculator{
public static void main (String [] args)
{
Scanner suslady = new Scanner(System.in);

int remander, answer;
System.out.print("Enter 1st # ");
String inp1 = suslady.nextLine();
int fnum=Integer.parseInt(inp1);
System.out.print("Enter Operation");
String operat = suslady.nextLine();
System.out.print ("Enter 2nd # ");
String sm = suslady.nextLine();
int snum=Integer.parseInt(sm);



Thanks dude it work great! :) :) :)

if(operat.equals("+"))
{
answer = fnum + snum;
System.out.print ("Answer: ");
System.out.println (answer);
}

if(operat.equals("-"))
{
answer = fnum - snum;
System.out.print ("Answer: ");
System.out.println (answer);
}

if(operat.equals("*"))
{
answer = fnum * snum;
System.out.print ("Answer: ");
System.out.println (answer);
}

if(operat.equals("/"))
{
remander = fnum % snum;
answer = fnum / snum;
System.out.print ("Answer: ");
System.out.println (answer);
System.out.print ("Remander: ");
System.out.println (remander);
}
}
}

Use this.It's working properly.

Thanks so much it work great! :) :) :) :)

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