Java Math

The relevant code

package q;

import java.util.Scanner;

public class text
{
public static void main (String[] args){

Cal cal= new Cal(8,4);

System.out.println("8+4="+cal.add() );

System.out.println("8-4="+cal.sub() );

System.out.println("8*4="  +cal.mul() );

System.out.println("8/4="  +cal.div() );

}
}
class Cal{

int x,y;

Cal(int a,int b)//构造函数
{
x=a;

y=b;
}

int add(){return x+y;}

int sub() {return x-y;}

int mul() {return x*y;}

int div() {return x/y;}

}

Possible errors:

If No enclosing instance of type text is accessible appears Must qualify the allocation with an enclosing instance of type text (egxnew A () where x is an instance of text) error.
Cause of error:
cause on the static class for class,
solution:
the class takeout, you can correct the error on the static

Published 38 original articles · won praise 0 · Views 1128

Guess you like

Origin blog.csdn.net/weixin_45489155/article/details/104833166