Can someone smart explain to my dumbass why my reverse array method will not work correctly

Can someone smart explain to my dumbass why my reverse array method will not work correctly

Other urls found in this thread:

stackoverflow.com/questions/40480/is-java-pass-by-reference-or-pass-by-value
twitter.com/AnonBabble

declare temp outside of the for scope

Still the same output

cast temp to float

Wouldn't be possible, that would be an incompabitable type for double array to float

you're mom is a double array

Arrays are pass by value. Retard.

(you)

Take ReverseArray out of the for loop in main. Retard

ding ding ding, you are the winner. But someone on /dpt/ helped me out. Here is your congratulatory (you) for trying

it's pretty alarming what kind of nonsense everybody pointed out before this

class Box{
double[] dataSet;
}

it's about when java uses copy of object and when it uses it's reference...

No it's not.

why is he even using for loop in main? and yes it creates copy off array and works on it in ReverseArray(double[] array)

>Is Java “pass-by-reference” or “pass-by-value”?
stackoverflow.com/questions/40480/is-java-pass-by-reference-or-pass-by-value

You have to box your data to manipulate on the insides from other methods...

The fuck. Why are you reversing for every item in the dataset

Pass by reference would need a pointer, so I think that's why Java never implemented this

So much wrong here,OP.

You're over complicating a really simple task, I doubt you need to worry about performance (to whatever it was you were aiming for) in a homework assignment, just correctness.

You need a function that takes an array and returns the reversed array. So much less code, also using a generic in the type signature allows the function to work for any type of array.

Here's it in Swift, because do your own homework.

//: Playground - noun: a place where people can play

import UIKit

// Truncated for sanity
let data = [4758.806, 5795.711, 5014.683, 7701.312, 3246.816, 6989.659, 5027.365, 7440.575, 3019.995, 7241.105, 7696.65]

func reversedArray(array: [T]) -> [T] {

var reversed = [T]()

for item in array {
reversed.insert(item, at: 0)
}

return reversed
}

print("There are \(data.count) items")

print("Reversed: \n \(reversedArray(array: data))")

exactly, return new array, you would use c if it was about performance

Collections.reverse(Arrays.asList(array));

Stop re-inventing the wheel user.

The point was obviously to invent some part of the wheel.

"You are wrong OP, let me show you an example in this meme language you probably dont know".

Write it in c then use jni to connect it to java.

Or do it objective style...

int[] normal_array = { 0, 1, 2, 3 };

int[] reversed_array = new int[normal_array.lenght];

int position = normal_array.lenght;

for (int i = 0; i < normal_array.lenght; i++)
{
reversed_array[position] = normal_array[i];
position--;
}

wow, Swift looks very similar to Python. Had no idea.

>mfw people in this thread either can't reverse an array or have to write a ton of code to do it

dataset = [0, 1, 2, 3, 4]
dataset.reverse()
print(f'Reversed Array: {dataset}')


>mfw people call python a meme language because it allows you to get things done faster and with less code

>"hey user, for this assignment you have to write a function that reverses an array"
>wow im so smart, I'll use a premade function of the standard library

>I'll roll the wheel down hill instead of trying to invent the wheel from scratch

That's right user. While you're working on monotonous projects that were figured out 50 years ago, I'll be inventing new things and moving towards the future.

>What is learning?

are you literally stupid?

That's an ASSIGNMENT, but probably you don't even know what that is, right? Too much time living in your mother's basement

>meme language
Safety isn't a meme user

>apple meme language
>is not a meme

class Reverter{
double[] array;

Reverter(double[] array){
this.array = array;
}
void set(double[] array){
this.array = array;
}
void get(){
return array;
}
void reverse(){
for(int i=0; i

Okay, so serious question what complaints do you have against Swift?

disgusting

show better

you wrote a class, with 1 field in it and 1 useful method in it. Why.

Show a better way for doing it in fucking java.

>are you stupid
>you living your mother's basement

Not an argument, try again user.

OP's broken way is better than your way. You should feel ashamed.

Do you even know java? You should kill yourself or write better code.

>don't do what the assignment asked
>not stupid

pick one

it wouldn't be stupid if assignment said just to revert in java... other annon btw

WRITE reverse function in java, not USE premade function in java

You've got to calm down dude. Your autism is showing.

Op never said it, welcome back op. Dragon dildo up your ass might help.

data = [1, 2, 3, 4, 5]

for item in data:
data.remove(item)
data.insert(0, item)

print(data)


python rules, java drools.

Op, he's right, write it in python.

You're reversing array on every iteration, dumbass.

It's almost as if half of Sup Forums is only here for the circle jerk.

First, put spaces around binary operators.

Then we'll talk.

> O(N^2) reverse function

literally kill yourself

My implementation is still the best one unless you're caring about a few nanoseconds of execution time

private int[] Revert(int[] dataset)
{
int[] temp = new int[dataset.lenght];

int position = dataset.lenght;

for(int i = 0; i < dataset.lenght; i++)
{
temp[position] = dataset[i];
position--;
}
return temp;
}

holy shit, an entire class for a single function?

That's why people here hate OOP

>lenght
>position is wrong
nice try though

Just to spite this fag you should change the variable declaration over anything spelling related.

because it's for stupid people