Advertisement
Guest User

baki1

a guest
Dec 12th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. import java.awt.*;
  2. import java.util.Arrays;
  3. import java.util.Scanner;
  4.  
  5. public class Aufgabe2 {
  6.  
  7. private static void printArrayContent(int[] currentArray){
  8. // TODO: Implementieren Sie hier Ihre Lösung für die Angabe
  9.  
  10. System.out.println(Arrays.toString(currentArray));
  11.  
  12. StdDraw.setCanvasSize(500,550);
  13. StdDraw.setXscale(0,500);
  14. StdDraw.setYscale(0,550);
  15. StdDraw.setPenRadius(0.003);
  16.  
  17. StdDraw.setPenColor(Color.BLACK);
  18.  
  19. for (int w = 0; w<500; w+=50){
  20.  
  21. int val = currentArray[w/50];
  22.  
  23. StdDraw.setPenColor(Color.BLACK);
  24. StdDraw.square(w+25,25,25);
  25. StdDraw.setPenColor(Color.BLUE);
  26. StdDraw.text(w+25,25,val+"");
  27.  
  28. for (int m = 50; m<550; m+=50){
  29. if (val > 0){
  30. StdDraw.setPenColor(Color.GREEN);
  31. StdDraw.filledCircle(w+25,m+25,10);
  32. val--;
  33. }
  34. }
  35.  
  36. }
  37.  
  38.  
  39. }
  40.  
  41. public static void main(String[] args) {
  42. // TODO: Implementieren Sie hier Ihre Lösung für die Angabe
  43.  
  44.  
  45.  
  46. int [] array = new int[10];
  47.  
  48. Scanner scanner = new Scanner(System.in);
  49.  
  50. String errorMessage = "Invalid input.Please enter Integer between 0-10";
  51.  
  52. int index = 0;
  53.  
  54. while (true) {
  55.  
  56.  
  57. while (scanner.hasNextInt()) {
  58. int x = scanner.nextInt();
  59. if (x >= 0 && x < 10 ) {
  60. array[index % 10] = x;
  61. index++;
  62.  
  63. }
  64.  
  65. else {
  66. System.out.println(errorMessage);
  67. }
  68.  
  69. }
  70.  
  71.  
  72. String input = scanner.next();
  73.  
  74.  
  75. if (input.equals("exit")){
  76. printArrayContent(array);
  77. return;
  78. }
  79.  
  80. else if (input.equals("print"))
  81. {
  82. printArrayContent(array);
  83. }
  84.  
  85. else{
  86. System.out.println(errorMessage);
  87. }
  88.  
  89. }
  90.  
  91. }
  92.  
  93.  
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement