rooq37

Untitled

Nov 20th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. def operacjaTablicowa(tab:Array[Int],op:String,value:Int):Array[Int] =
  2. op match {
  3. case "sum" => {
  4. val temp = new Array[Int](1)
  5. var sum = 0;
  6. for ( i <- 0 to (tab.length - 1)) {
  7. sum = (sum + tab(i));
  8. }
  9. temp(0) = sum
  10. return temp
  11. }
  12. case "add" => {
  13. val temp = new Array[Int](tab.length+1)
  14. for(i <- 0 to (tab.length -1)){
  15. temp(i) = tab(i)
  16. }
  17. temp(temp.length-1) = value
  18. return temp
  19. }
  20. case "remove" =>{
  21. val temp = new Array[Int](tab.length-1)
  22. var index = 0;
  23. for(i <- 0 to (tab.length-1)){
  24. if(i != value){
  25. temp(index) = tab(i)
  26. index = index + 1
  27. }
  28. }
  29. return temp
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment