Question: > 
> excepted output : 1/4,1/2,3/4,1,5/4,3/2
>  but my output is coming as in the decimal form . Please help how to print in the form of fraction only.
> 
> 
> 

```
import java.util.*;
public class Hello {

public static void main(String[] args) {
    //Your Code Here
    Scanner s=new Scanner(System.in);
    int n=s.nextInt();
    double d=1/4.0,sum=0;
    for(int i=0;i<n;i++) {
        sum+=d;
        System.out.print(sum+" ");
    }

}}

```

Answer: 
take input in form of string so it will take input in required format and split it by "/" i.e someString.spit("/").
after that make one for loop and take two number and in two different variable store it.
and then take division for both and print it by using "/" in between them.
Wrote a method where you can convert double numbers to fraction. Use this to convert it and print as below,

```
import java.util.Scanner;

public class test {
    public static void main(String[] args) {
        Scanner s=new Scanner(System.in);
        int n=s.nextInt();
        double d=1/4.0,sum=0;
        for(int i=0;i<n;i++) {
            sum+=d;
            System.out.print(toFraction(sum)+" ");
        }

    }

    static String toFraction(double x) {
        int w = (int) x;
        int n = (int) (x * 64) % 64;
        int a = n & -n;
        return n == 0 ? w+"" : (w * (64 / a) + (n / a)) + "/" + 64 / a;
    }
}

```