Answers for "java how to use method class"

1

java classes and methods

import java.lang.Math;
import java.util.Scanner;

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

            double number;

            public boolean isSquare(double number) {

                double result = Math.sqrt(number);
                return ((result - Math.floor(result)) == 0);

            }
        }

        ResultNumberShape checkNumber = new ResultNumberShape();

        System.out.println("Enter any number:");
        Scanner scanner = new Scanner(System.in);
        double num = scanner.nextDouble();

        scanner.close();

        if (checkNumber.isSquare(num)) {
            System.out.println(num + " is a sqaure number!");
        } else {
            System.out.println(num + " is not a square!");
        }
    
  }
}
Posted by: Guest on March-13-2020
3

java methods

public class MyClass {
  static int myMethod(int x) {
    return 5 + x;
  }

  public static void main(String[] args) {
    System.out.println(myMethod(3));
  }
}
// Returns 8
Posted by: Guest on June-02-2020

Code answers related to "java how to use method class"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language