Skip to content

Instantly share code, notes, and snippets.

@mukulchauhan10
Created November 19, 2019 11:26
Show Gist options
  • Save mukulchauhan10/59333ddbb020fd5c92c03a19303d8b88 to your computer and use it in GitHub Desktop.
Save mukulchauhan10/59333ddbb020fd5c92c03a19303d8b88 to your computer and use it in GitHub Desktop.
Logic Loop
package complex;
import java.util.*;
public class Main {
public static void main(String[] kallu) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter size of loop (between 1-9) = ");
int t=1;
while(t>0){
if(t>1){
System.out.print("Enter next = ");
}
t++;
int full = sc.nextInt();
if (full > 0 && 10 > full) {
for (int i = 1; i <= full; i++) {
int k = i;
for (int j = 1; j <= full - i; j++) {
System.out.print(" ");
}
for (int j = 1; j <= i; j++) {
System.out.print(j + " ");
}
for (int m = 1; m <= i - 1; m++) {
System.out.print((k - 1) + " ");
k--;
}
System.out.println();
}
for (int i = 1; i <= full - 1; i++) {
int g = full - i;
for (int j = 1; j <= i; j++) {
System.out.print(" ");
}
for (int j = 1; j <= full - i; j++) {
System.out.print(j + " ");
}
for (int j = 1; j <= full - i - 1; j++) {
System.out.print((g - 1) + " ");
g--;
}
System.out.println();
}
System.out.print("---------------------------------\n\n");
}
else{
System.out.print("\nOops!!! Wrong input ....\n Try again (Range = 1-9)\n");
System.out.print("---------------------------------\n\n");
}
}
}
}
@mukulchauhan10
Copy link
Author

hi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment