简体   繁体   English

我正在尝试制作一个java数组代码

[英]I'm trying to make a java array code

i'm trying to build a code for different actions in arrays with different methods (Constructors) but i cannot seem to find a way to link them...I've made a array with 100 elements and a random variable to fill it....i'd like to know how to get my random elements from the first methods to the second one to make the comparing.... and also i'd like to not include in the 0 element in the random generator..any help? 我正在尝试使用不同的方法(构造函数)为数组中的不同操作构建代码,但我似乎无法找到链接它们的方法...我已经创建了一个包含100个元素和随机变量的数组来填充它。 ...我想知道如何将我的随机元素从第一个方法转换到第二个方法来进行比较....而且我也不想包含在随机生成器的0元素中..任何帮助?

this is my code 这是我的代码

import java.util.*;

public class prova1{
    public int min;

    public void tabele(){
        Random r = new Random();
        int d;
        int e[]= new int[100];
        for(int i=0; i<e.length;i++){
            d=r.nextInt(100);
            e[i]=d;
            System.out.println(e[i]);
        }
    }
    public void emin(){
        Random r = new Random();
        int d;
        int e[]=new int[100];
        for(int i=0; i<e.length;i++){
            d=r.nextInt(100);
            e[i]=d;
            if(e[i]<min){
                min=e[i];
            }
        }
        System.out.println("Vlera me e vogel eshte: " +min);

    }
    public static void main(String []args){
        prova1 prova = new prova1();
        prova.tabele();
        prova.emin();   
    }
}

Return the array from tabele to a local variable and send it as parameter to emin 将数组从tabele返回到局部变量,并将其作为参数发送给emin

import java.util.*;

public class prova1 {
    public int min;

    public int[] tabele() {
        Random r = new Random();
        int d;
        int e[]= new int[100];
        for(int i=0; i<e.length;i++){
            d=r.nextInt(99) + 1;
            e[i]=d;
            System.out.println(e[i]);
        }

        return e;
    }

    public void emin(int[] e) {
        Random r = new Random();
        int d;
        for(int i=0; i<e.length;i++) {
            if(e[i]<min) {
                min=e[i];
            }
        }

        System.out.println("Vlera me e vogel eshte: " +min);
    }

    public static void main(String []args){
        prova1 prova = new prova1();
        int[] arr = prova.tabele();
        prova.emin(arr);
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我正在尝试制作 Java 文件服务器 - I'm trying to make a Java File Server Java-我试图做一个计时器 - Java - I'm trying to make a timer 我正在尝试使用GUI在Java中制作计算器 - I'm Trying To Make A Calculator in Java with a GUI 我正在尝试制作一个可以创建密码的Java程序 - I'm trying to make a java program that creates passwords 这行得通吗? 我正在尝试制作一个多维数组,我很确定它可以在Java中工作,但是我不了解C ++ - Would this work? I'm trying to make a multi-dimensional array, and I'm pretty sure it would work in Java, but I don't know about C++ 我正在尝试循环 - I'm trying to make a loop 我正在尝试使用java更新数据库。 我在netbeans中工作,代码中没有错误,但行仍未更新 - I'm trying to update my database with java . i'm working in netbeans , there no error in the code but still the rows are not updated 我正在尝试使用多行扫描仪并尝试使用另一个字符串 java 更改输入 - I'm trying to use the scanner with multiple lines and trying to make change the input with another string java 我正在尝试制作一个简单的程序,用“*”符号替换&#39;a&#39;,&#39;e&#39;,&#39;i&#39;,但我收到此错误代码 - I am trying make a simple program that replaces 'a', 'e', 'i' with the “*” symbol but i'm getting this error code 我正在尝试使用 Java 的 HttpURLConnection 进行“条件获取”,但我从未得到 304 状态码 - I'm trying to use Java's HttpURLConnection to do a “conditional get”, but I never get a 304 status code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM