用java实现输出G位0和一位1组成的字符串

第G组的字符组成为G个0和1个1,例如第3组为0001,第5组为000001,请问我如何用java代码实现?


package com;

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        String res = String.format("%0" + (n + 1) + "d", 1);
        System.out.println(res);
        input.close();

    }

}

img

img