NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

вектор
import java.util.Arrays;

public class Vector {
private final int length;
private final int[] elements;

public Vector(int length) {
this.length = length;
this.elements = new int[length];
}

public int getElement(int index) {
if (index < 0 || index >= length) {
throw new IndexOutOfBoundsException();
}
return elements[index];
}

public void setElement(int index, int value) {
if (index < 0 || index >= length) {
throw new IndexOutOfBoundsException();
}
elements[index] = value;
}

public int getLength() {
return length;
}

public int getMinValue() {
int min = elements[0];
for (int i = 1; i < length; i++) {
if (elements[i] < min) {
min = elements[i];
}
}
return min;
}

public int getMaxValue() {
int max = elements[0];
for (int i = 1; i < length; i++) {
if (elements[i] > max) {
max = elements[i];
}
}
return max;
}

public void sort() {
Arrays.sort(elements);
}

public double getEuclideanNorm() {
double norm = 0;
for (int i = 0; i < length; i++) {
norm += Math.pow(elements[i], 2);
}
return Math.sqrt(norm);
}

public void multiplyByScalar(int scalar) {
for (int i = 0; i < length; i++) {
elements[i] *= scalar;
}
}

public Vector add(Vector other) {
if (length != other.length) {
throw new IllegalArgumentException("Vectors must have the same length");
}
Vector result = new Vector(length);
for (int i = 0; i < length; i++) {
result.elements[i] = elements[i] + other.elements[i];
}
return result;
}

public int getScalarProduct(Vector other) {public class Main {
public static void main(String[] args) {
Vector vector = new Vector(5);

// Установка значений элементов
vector.setElement(0, 1);
vector.setElement(1, 2);
vector.setElement(2, 3);
vector.setElement(3, 4);
vector.setElement(4, 5);

// Получение значения элемента
int element = vector.getElement(2);
System.out.println("Element at index 2: " + element);

// Длина вектора
int length = vector.getLength();
System.out.println("Vector length: " + length);

// Минимальное и максимальное значения
int minValue = vector.getMinValue();
int maxValue = vector.getMaxValue();
System.out.println("Min value: " + minValue);
System.out.println("Max value: " + maxValue);

// Сортировка вектора
vector.sort();

// Евклидова норма
double euclideanNorm = vector.getEuclideanNorm();
System.out.println("Euclidean norm: " + euclideanNorm);

// Умножение на число
vector.multiplyByScalar(2);

// Сложение двух векторов
Vector otherVector = new Vector(5);
otherVector.setElement(0, 2);
otherVector.setElement(1, 4);
otherVector.setElement(2, 6);
otherVector.setElement(3, 8);
otherVector.setElement(4, 10);

Vector sumVector = vector.add(otherVector);

// Скалярное произведение
int scalarProduct = vector.getScalarProduct(otherVector);
}
}

if (length != other.length) {
throw new IllegalArgumentException("Vectors must have the same length");
}
int product = 0;
for (int i = 0; i < length; i++) {
product += elements[i] * other.elements[i];
}
return product;
}
}
-------
public class Main {
public static void main(String[] args) {
Vector vector = new Vector(5);

// Установка значений элементов
vector.setElement(0, 1);
vector.setElement(1, 2);
vector.setElement(2, 3);
vector.setElement(3, 4);
vector.setElement(4, 5);

// Получение значения элемента
int element = vector.getElement(2);
System.out.println("Element at index 2: " + element);

// Длина вектора
int length = vector.getLength();
System.out.println("Vector length: " + length);

// Минимальное и максимальное значения
int minValue = vector.getMinValue();
int maxValue = vector.getMaxValue();
System.out.println("Min value: " + minValue);
System.out.println("Max value: " + maxValue);

// Сортировка вектора
vector.sort();

// Евклидова норма
double euclideanNorm = vector.getEuclideanNorm();
System.out.println("Euclidean norm: " + euclideanNorm);

// Умножение на число
vector.multiplyByScalar(2);

// Сложение двух векторов
Vector otherVector = new Vector(5);
otherVector.setElement(0, 2);
otherVector.setElement(1, 4);
otherVector.setElement(2, 6);
otherVector.setElement(3, 8);
otherVector.setElement(4, 10);

Vector sumVector = vector.add(otherVector);

// Скалярное произведение
int scalarProduct = vector.getScalarProduct(otherVector);
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.