[BAEL-11403] - Moved articles out of core-java (part 4)
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package com.baeldung.area.circle;
|
||||
|
||||
public class Circle {
|
||||
|
||||
private double radius;
|
||||
|
||||
public Circle(double radius) {
|
||||
this.radius = radius;
|
||||
}
|
||||
|
||||
public double getRadius() {
|
||||
return radius;
|
||||
}
|
||||
|
||||
public void setRadius(double radius) {
|
||||
this.radius = radius;
|
||||
}
|
||||
|
||||
private double calculateArea() {
|
||||
return radius * radius * Math.PI;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "The area of the circle [radius = " + radius + "]: " + calculateArea();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.baeldung.area.circle;
|
||||
|
||||
import java.util.InputMismatchException;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class CircleArea {
|
||||
|
||||
public static void main(String[] args) {
|
||||
if (args.length > 0) {
|
||||
try {
|
||||
double radius = Double.parseDouble(args[0]);
|
||||
calculateArea(radius);
|
||||
} catch (NumberFormatException nfe) {
|
||||
System.out.println("Invalid value for radius");
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
try (Scanner scanner = new Scanner(System.in)) {
|
||||
System.out.println("Please enter radius value: ");
|
||||
double radius = scanner.nextDouble();
|
||||
calculateArea(radius);
|
||||
} catch (InputMismatchException e) {
|
||||
System.out.println("Invalid value for radius");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
Circle circle = new Circle(7);
|
||||
System.out.println(circle);
|
||||
}
|
||||
|
||||
private static void calculateArea(double radius) {
|
||||
double area = radius * radius * Math.PI;
|
||||
System.out.println("The area of the circle [radius = " + radius + "]: " + area);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.baeldung.nth.root.calculator;
|
||||
|
||||
public class NthRootCalculator
|
||||
{
|
||||
public Double calculate(Double base, Double n) {
|
||||
return Math.pow(Math.E, Math.log(base)/n);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.baeldung.nth.root.main;
|
||||
|
||||
import com.baeldung.nth.root.calculator.NthRootCalculator;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
NthRootCalculator calculator = new NthRootCalculator();
|
||||
Double base = Double.parseDouble(args[0]);
|
||||
Double n = Double.parseDouble(args[1]);
|
||||
Double result = calculator.calculate(base, n);
|
||||
System.out.println("The " + n + " root of " + base + " equals to " + result + ".");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user