Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package hr.fer.oop.lab1.prob2;
- import java.lang.Math;
- public class Roots {
- public static void main(String[] args) {
- if(args.length!=3) System.out.println("Invalid number of arguments!");
- else if(Integer.parseInt(args[2])>1){
- calculateRoots(Double.parseDouble(args[0]),Double.parseDouble(args[1]), Integer.parseInt(args[2]));
- }else{
- System.out.println("Invalid argument! Root must be larger than 1!");
- }
- }
- public static void calculateRoots(double real, double complex, int root){
- System.out.printf("You requested calculation of %d roots. Solutions are:\n", root);
- for(int i=0; i<root; i++){
- Math.cos((2*Math.PI*i)/root);
- System.out.printf("%d) %.2f %s %.2fi\n", i, Math.cos((2*Math.PI*i)/root) , ( Math.sin((2*Math.PI*i)/root) > 0 ) ? "+":"-" , Math.abs( Math.sin((2*Math.PI*i)/root)) );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement