0
Hi😶 Does anyone know how to write a java program which has a static class and computs the square of numbers😣
I know that I can use ( import math) but don't know how in classes😔
4 odpowiedzi
+ 3
You cannot make a top level class static in Java, the compiler will not allow it, but you can make a nested class static in Java.
can't you just do like this:
class S{
public static void main(){
int n = 5;
int square = n*n;
System.out.println("Square is : " + square);
}
}
+ 2
// is this what you are looking for?
public class Temp{
static class Square{
int findSquare(int a){
return a*a;
}
}
public static void main(String[] args) {
Square square = new Square();
System.out.println("square of 5 is " +square.findSquare(5));
}
}
+ 1
Kind of tnx for your helping
0
Tnx, with this.
Do you know also about how to reference a variable to a static class and then print the result!??