Untitled
unknown
java
3 years ago
2.0 kB
8
Indexable
// Online Java Compiler
// Use this editor to write, compile and run your Java code online
import java.util.Random;
class HelloWorld {
// amocanebi 1
public interface NanoInterface {
public void setA(int a);
public void setB(int b);
public void setM();
}
// amocanebi 1
public class Nano implements NanoInterface {
private int a;
private int b;
private int[] m = new int[12];
// metodi 1
public void setA(int a) {
this.a = a;
}
// metodi 1
public void setB(int b) {
this.b = b;
}
// metodi 2
public void setM() {
Random rand = new Random();
for (int i = 0; i < 12; i++) {
int randomNum = rand.nextInt((this.a - this.b) + 1) + this.a;
this.m[i] = randomNum;
}
}
// metodi 3
public int getMinFromM() {
int min = this.m[0];
for (int i = 0; i < 12; i++) {
int arrItem = m[i];
if (arrItem > 0 && arrItem < min) {
min = arrItem;
}
}
return min;
}
// metodi 4
public void printElsWithIndex() {
for (int i = 0; i < 12; i++) {
int arrItem = this.m[i];
System.out.println("Index: " + i + ", " + "Value: " + arrItem);
}
}
// metodi 5
public void Metodi5() {
for (int i = 0; i < 12; i++) {
int arrItem = this.m[i];
if (arrItem % 3 == 0) {
System.out.println(arrItem);
}
}
}
}
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}Editor is loading...