Full width home advertisement

Java

Tech News

Ad

  1. package clgPracticals;
  2.  
  3. import java.util.Scanner;
  4.  
  5. class Pr4 {
  6. public static void main(String[] args) {
  7. Scanner s = new Scanner(System.in); // creating object
  8. int n;
  9. double ans = 0;
  10. System.out.print("\nEnter n ");
  11. n = s.nextInt(); // will Assign numarical value to n
  12. s.close();
  13.  
  14. // main logic
  15. for (int i = 1; i <= n; i++) {
  16. ans += 1 / (double) i;
  17. }
  18. System.out.println("the answer of series is " + ans);
  19. }
  20. }
  21.  

No comments:

Post a Comment

Bottom Ad [Post Page]