Computer Science, asked by Anonymous, 1 year ago

How to print the pattern ?
S = 1/2 + 2/3 + 3/4 ....................... n terms in java
I know the answer still asking so that I can give 10 easy points .
Imagine me as Santa Claus bfor Christmas,
Take 10 points but give a great answer
______________________________________________________

Answers

Answered by vaibhavsrivastava
1

I think the appropriate answer should be this :-


import java.util.Scanner;


class example


{


public static void main(String args[])


{


 Scanner in=new Scanner(System.in);


 System.out.print("Enter limit of series : ");


 int limit=in.nextInt();


 int i=1;


 while(i<=limit)


 {


  if(i!=1)


  {


   System.out.print(" + ");


  }


  System.out.print(i++"/"+i);


 }


}


}




Anonymous: correct that i+++ it should be i++. anyway thank u soo much :)
Answered by nirav0309
0

What is the program to print 1/2+2/3+3/4…n in java?

class Check{

public static void main(String args[]) {

double s=0;

for(int i=1;i<=5;i++) {

s=s+(double)i/(double)(i+1);

}

System.out.printf("%.2f",s); //”.2f” for upto 2 decimal places

}

}

output-

3.55 (for 2 decimal place)

3.5500000000000003

Similar questions