Findryan

Untitled

Nov 12th, 2016
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class NestedWhile
  3. {
  4. public static void main(String[]args)
  5. {
  6. Scanner input = new Scanner(System.in);
  7. System.out.println("Masukan angka");
  8. int n = input.nextInt();
  9. int i=1,j;
  10. while(i<=n)
  11. {
  12. j=1;
  13. if (i==1 || i==n)
  14. {
  15. while(j<=n)
  16. {
  17. System.out.print("* ");
  18. j++;
  19. }
  20. }
  21. else
  22. {
  23. while(j<=n)
  24. {
  25. if(j==1 || j==n)
  26. {
  27. System.out.print("* ");
  28. }
  29. else
  30. {
  31. System.out.print(" ");
  32. }
  33. j++;
  34. }
  35. }
  36. System.out.print("\n");
  37. i++;
  38. }
  39. }
  40. }
Add Comment
Please, Sign In to add comment