Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def operacjaTablicowa(tab:Array[Int],op:String,value:Int):Array[Int] =
- op match {
- case "sum" => {
- val temp = new Array[Int](1)
- var sum = 0;
- for ( i <- 0 to (tab.length - 1)) {
- sum = (sum + tab(i));
- }
- temp(0) = sum
- return temp
- }
- case "add" => {
- val temp = new Array[Int](tab.length+1)
- for(i <- 0 to (tab.length -1)){
- temp(i) = tab(i)
- }
- temp(temp.length-1) = value
- return temp
- }
- case "remove" =>{
- val temp = new Array[Int](tab.length-1)
- var index = 0;
- for(i <- 0 to (tab.length-1)){
- if(i != value){
- temp(index) = tab(i)
- index = index + 1
- }
- }
- return temp
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment