Print a Floyd’s triangle having n rows.
import java.util.Scanner; class triangle { public static void main(String arg[]) { Scanner input=new Scanner(System.in); System.out.println("Enter number of rows: "); int num; int ab=0; num=input.nextInt(); System.out.println(); System.out.println(); for(int i=1;i<=num;i++) { for(int j=1;j<=i;j++) { if(ab==0) { ab=1; System.out.print(ab); } else { ab=0; System.out.print(ab); } } System.out.println(); } } }