Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Uppgift3 {
  4. public static void main(String[] args) {
  5.  
  6. Scanner scan = new Scanner(System.in);
  7.  
  8. int direction=0, length;
  9. char ch;
  10.  
  11. while (true)
  12. {
  13. System.out.print("\nAnge längden på de 2 lika länga sidorna 1-26 (avsluta med -1):");
  14. length = scan.nextInt();
  15.  
  16. if(length == -1)
  17. {
  18. break;
  19. }
  20. if(length>26)
  21. {
  22. break;
  23. }
  24. System.out.print("Ska den räta vinkeln vara nedåt (0) eller uppåt (1):");
  25. direction = scan.nextInt();
  26.  
  27. if(direction == 0)
  28. {
  29. for(int i=1;i<=length;i++)
  30. {
  31. System.out.print("\n");
  32. ch = 'A';
  33.  
  34. for(int j=1; j<=length; j++)
  35. if (j<=i)
  36. {
  37. System.out.print( ch);
  38. ch++;
  39. }
  40.  
  41. }
  42.  
  43. }
  44. else if(direction == 1)
  45. {
  46. for(int i=1;i<=length;i++)
  47. {
  48. System.out.print("\n");
  49. ch = 'A';
  50.  
  51. for(int j=length;j>=1;j--)
  52. if (j>=i)
  53. {
  54. System.out.print(ch);
  55. ch++;
  56. }
  57. }
  58. }
  59. }
  60.  
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement