willieshi232

Untitled

Sep 19th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.78 KB | None | 0 0
  1. /**
  2. * Created by WillieShi on 9/9/2017.
  3. */
  4. import java.util.*;
  5. public class InsertArray
  6. {
  7. public static void main(String []args)
  8. {
  9. int[] current = {1,2,3,4};
  10. int[] newboi = new int[current.length+1];
  11. int toadd;
  12. String command;
  13. Scanner console = new Scanner(System.in);
  14. System.out.println("Start, end, or index?");
  15. command = console.next();
  16. System.out.println("Gimme the number");
  17. toadd = console.nextInt();
  18. if(command == "Start")
  19. {
  20. for(int i = 0; i < newboi.length; i++)
  21. {
  22. if(i == 0)
  23. {
  24. newboi[i] = toadd;
  25. }
  26. else
  27. {
  28. newboi[i] = current[i-1];
  29. }
  30.  
  31. }
  32. }
  33. else if(command == "end")
  34. {
  35. for(int i = 0; i < newboi.length; i++)
  36. {
  37. if(i == newboi.length)
  38. {
  39. newboi[i] = toadd;
  40. }
  41. else
  42. {
  43. newboi[i] = current[i];
  44. }
  45.  
  46. }
  47. }
  48. else if(command == "index")
  49. {
  50. int index;
  51. boolean indexadded = false;
  52. System.out.println("Gimme the index");
  53. index = console.nextInt();
  54. for(int i = 0; i < newboi.length; i++)
  55. {
  56. if(indexadded = false)
  57. {
  58. newboi[i] = current[i];
  59. }
  60. else if(i == index)
  61. {
  62. newboi[i] = toadd;
  63. indexadded = true;
  64. }
  65. else if(indexadded = true)
  66. {
  67. newboi[i] = current[i-1];
  68. }
  69.  
  70. }
  71. }
  72. else if(command = "index+1")
  73. {
  74. int index;
  75. boolean indexadded = false;
  76. System.out.println("Gimme the index");
  77. index = console.nextInt();
  78. for(int i = 0; i < newboi.length; i++)
  79. {
  80. if(indexadded = false)
  81. {
  82. newboi[i] = current[i];
  83. }
  84. else if(i == index+1)
  85. {
  86. newboi[i] = toadd;
  87. indexadded = true;
  88. }
  89. else if(indexadded = true)
  90. {
  91. newboi[i] = current[i-1];
  92. }
  93.  
  94. }
  95. }
  96. else if(command = "input-1")
  97. {
  98. int index;
  99. boolean indexadded = false;
  100. System.out.println("Gimme the index");
  101. index = console.nextInt();
  102. if(index == 0)
  103. {
  104. System.out.println("You're dumb kiddo");
  105. System.exit(0);
  106. }
  107. for(int i = 0; i < newboi.length; i++)
  108. {
  109. if(indexadded = false)
  110. {
  111. newboi[i] = current[i];
  112. }
  113. else if(i == index)
  114. {
  115. newboi[i] = toadd;
  116. indexadded = true;
  117. }
  118. else if(indexadded = true)
  119. {
  120. newboi[i] = current[i-1];
  121. }
  122.  
  123. }
  124. }
  125. else if(command == "update")
  126. {
  127. int index;
  128. System.out.println("Gimme the updated index");
  129. index = console.nextInt();
  130. currentboi[index] = toadd;
  131. }
  132. System.out.println("OldArray" + Arrays.toString(current));
  133. System.out.println("NewArray" + Arrays.toString(newboi));
  134. }
  135.  
  136. }
Advertisement
Add Comment
Please, Sign In to add comment