Cellular distribut
Fantasy Sports
Wh
Q:
Why a pointer
A. Field of the In
A new approach to
All relevant data
[A case of maligna
Q:
How do I make
Falcon Northwest
Introduction
=====Q:
Is there any method to make this method to show the string?
I wrote a code in Java to make a calculator.
but when I run it it just gives an error.
I will show you the code:
This is the Main class:
package JavaApplication10;
public class JavaApplication10 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Calculator c = new Calculator();
c.add(5,10);
}
}
This is the Calculator class:
package JavaApplication10;
import java.util.Scanner;
import java.util.InputMismatchException;
import java.util.InputMismatchException;
import java.util.InputMismatchException;
import java.util.Scanner;
public class Calculator {
private int a,b;
public void add(int x,int y) {
Scanner input=new Scanner(System.in);
Scanner input1=new Scanner(System.in);
System.out.println("enter two numbers");
System.out.println("Press 0 if you want to exit the program");
System.out.println("Enter the first number");
a=input.nextInt();
System.out.println("Enter the second number");
b=input1.nextInt();
int z=a+b;
System.out.println(z);
}
public void subtract(int x,int y) {
Scanner input=new Scanner(System.in);
Scanner input1=new Scanner(System.in);
System.out.println("Enter the first number");
a=input.nextInt();
System.out.println("Enter the second number");
b=input1.nextInt();
int z=a-b;
System.out.println(z);
}
public void substract(int x,int y) {
Scanner input=new Scanner(System.in);
Scanner input1=new Scanner(System.in);
System.out.println("Enter the first number");
a=input.nextInt();
System.out.println("Enter the second number");
b=input1.nextInt();
int z=a-b;
System.out.println(z);
}
public void multiply(int x,int y) {
Scanner input=new Scanner(System.in);
Scanner input1=new Scanner(System.in);
System.out.println("Enter the first number");
a=input.nextInt();
System.out.println("Enter the second number");
b=input1.nextInt();
int z=a*b;
System.out.println(z);
}
public void multiply(int x,int y) {
Scanner input=new Scanner(System.in);
Scanner input1=new Scanner(System.in);
System.out.println("Enter the first number");
a=input.nextInt();
System.out.println("Enter the second number");
b=input1.nextInt();
int z=a*b;
System.out.println(z);
}
public void divide(int x,int y) {
Scanner input=new Scanner(System.in);
Scanner input1=new Scanner(System.in);
System.out.println("Enter the first number");
a=input.nextInt();
System.out.println("Enter the second number");
b=input1.nextInt();
int z=a/b;
System.out.println(z);
}
public void divide(int x,int y) {
Scanner input=new Scanner(System.in);
Scanner input1=new Scanner(System.in);
System.out.println("Enter the first number");
a=input.nextInt();
System.out.println("Enter the second number");
b=input1.nextInt();
int z=a/b;
System.out.println(z);
}
public void pow(int x,int y) {
Scanner input=new Scanner(System.in);
Scanner input1=new Scanner(System.in);
System.out.println("Enter the first number");
a=input.nextInt();
System.out.println("Enter the second number");
b=input1.nextInt();
int z=a^b;
System.out.println(z);
}
public void pow(int x,int y) {
Scanner input=new Scanner(System.in);
Scanner input1=new Scanner(System.in);
System.out.println("Enter the first number");
a=input.nextInt();
System.out.println("Enter the second number");
b=input1.nextInt();
int z=a^b;
System.out.println(z);
}
}
but when I run the main class this error occurs:
C:\Users\Alireza\Desktop>javac JavaApplication10.java
JavaApplication10.java:16: error: cannot find symbol
Calculator c = new Calculator();
^
symbol: class Calculator
location: class JavaApplication10
1 error
I have not understood why this happens. It might be because of the main method?
can you help me please?
thanks.
A:
Your error is the definition of your class Calculator. You are missing the public keyword after your class name:
public class Calculator{
...
}
Also note that your compiler will probably be in the path if you are using a normal IDE. So you could just do:
java JavaApplication10
Otherwise, you can make the compiler find it in the current working directory by running:
C:\Users\Alireza\Desktop>javac C:\\Users\\Alireza\\JavaApplication10
\JavaApplication10\Calculator.java
Or if you are running in a different directory:
C:\Users\Alireza>cd C:\\Users\Alireza\\JavaApplication10
C:\Users\Alireza\JavaApplication10>javac Calculator.java