Advertisement
Guest User

Untitled

a guest
Oct 17th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. package hr.fer.oop.lab1.prob2;
  2. import java.lang.Math;
  3.  
  4. public class Roots {
  5.  
  6. public static void main(String[] args) {
  7. if(args.length!=3) System.out.println("Invalid number of arguments!");
  8. else if(Integer.parseInt(args[2])>1){
  9. calculateRoots(Double.parseDouble(args[0]),Double.parseDouble(args[1]), Integer.parseInt(args[2]));
  10. }else{
  11. System.out.println("Invalid argument! Root must be larger than 1!");
  12. }
  13. }
  14.  
  15.  
  16.  
  17. public static void calculateRoots(double real, double complex, int root){
  18. System.out.printf("You requested calculation of %d roots. Solutions are:\n", root);
  19. for(int i=0; i<root; i++){
  20. Math.cos((2*Math.PI*i)/root);
  21. 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)) );
  22.  
  23. }
  24.  
  25. }
  26.  
  27.  
  28.  
  29.  
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement