Pr_robot_factory/domain/R2D2.java

47 lines
1.0 KiB
Java
Raw Normal View History

2022-12-08 14:58:44 +01:00
package domain;
2022-12-14 09:48:20 +01:00
import robot.interfaces.Sorting;
import java.util.Arrays;
2022-12-09 00:30:35 +01:00
public class R2D2 extends RobotBasics {
/**
* Constructor
* @param id> int
* @param name> String
*/
public R2D2(int id, String name){
super(id, name);
2022-12-14 09:48:20 +01:00
}
2022-12-14 09:48:20 +01:00
public String sorting(int[] arr) {
//Selectionsort
int small;
for (int i = 0; i <arr.length - 1; i++) {
small = i;
for (int j = i + 1; j < arr.length; j++) {
//if there is a smaller number on this position
if (arr[j] < arr[small]) {
small = j;
//swap values
int temp = arr[i];
arr[i] = arr[small];
arr[small] = temp;
}
}
}
//Writing all values of the array into a String
String result = "";
if(arr.length != 0) {
result = "" + arr[0];
if (arr.length > 1) {
for (int i = 1; i < arr.length; i++) {
result += "," + arr[i];
}
}
}
return result;
}
2022-12-08 14:58:44 +01:00
}