不确定如何为向量设置统一值 [英] Unsure how to set uniform value to a vector

查看:28
本文介绍了不确定如何为向量设置统一值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个问题,我有一个向量类,如果用户想为他们输入的 int 设置一个统一的值.这是我目前的代码:

So i have a problem where i have a vector class, and if the user wants to set a uniform value to the int they type in. This is my code so far:

public static Vector uniform(int length, long value) {

    /*
        EXAMPLE
        length 4, value 4 => [4 4 4 4]
    */

    Vector vector = new Vector(length);

    //for loop to iterate through each elements & set value?

    return new Vector(length);
}

有提醒的部分是我不确定的部分.当向量主程序运行并且用户输入Set a = uniform 4"时,数字4必须成为向量中所有数字的值.我该怎么做?

The part with the reminder was the part i was unsure about. When the vector main program is run and the user types in "Set a = uniform 4", then the number 4 must become the value for all the numbers in the vector. How can i do this?

推荐答案

假设 Vectors 类名打错了,实际上是 Vector:

Assuming the Vectors class name is a typo, and it's actually Vector:

Vector v = new Vector(length);
Arrays.fill(v.elements, value);
return v;

这篇关于不确定如何为向量设置统一值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆