cw

mail@pastecode.io avatar
unknown
java
2 months ago
2.2 kB
12
Indexable
Never
//c1

public class ClassworkOne {
    public static void evenChecker(int number) {
        if (number % 2 == 0) {
            System.out.println("Even!!");
        }
        else {
            System.out.println("Odd!!");
        }
    }
    public static boolean isEven(int number){
        return number % 2 == 0;
    }
    public static boolean isPos(int number){
        return number > -1;
    }
    public static void sequence(int n){
        if(isPos(n)){
            for (int i = 0; i <= n; i+=2){
                System.out.print(i+" ");
            }
        }
        else if (isEven(n)){
            for (int i = n + 1 ; i <= -1; i+=2){
                System.out.print(i+" ");
            }
        }
        else {
          for (int i = n ; i <= -1; i+=2) {
            System.out.print(i + " ");
          }
        }
        System.out.println("");
        
    }
    public static void main(String[] args){
        evenChecker(10);
        evenChecker(17);
        boolean result = isEven(10);
        System.out.println( result );
        result = isEven(17);
        System.out.println( result );
        result = isPos(-5);
        System.out.println( result );
        result = isPos(12);
        System.out.println( result );
        sequence(10);
        sequence(-7);
        sequence(7);
        sequence(-8);
    }
}

//c2

public class ClassworkTwo {
  public static double circleArea(int radius) {
    return 3.1416 * radius * radius;
  
  }
  
  public static double sphereVolume(int radius) {
    double pi = 3.14159;
    return 4.0/3.0 * pi  * radius * radius * radius;
  
  }
  
  public static void findSpace(int diameter, String s) {
    int radius = diameter / 2;
    if (s.equals("circle")) {
      System.out.println(circleArea(radius));
    
    }
    else if (s.equals("sphere")) {
      System.out.println(sphereVolume(radius));
    }
    else {
      System.out.println("Wrong parameter");
    }
    
  
  }
  
  public static void main(String[] args) {
    double area = circleArea(5);
    System.out.println(area);
    findSpace(10, "circle");
    double volume = sphereVolume(5);
    System.out.println(volume);

  
  
  }

}
Leave a Comment