Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 根据用户输入的最高分对邮件进行排序_Java_Arrays_Sorting_Java.util.scanner - Fatal编程技术网

Java 根据用户输入的最高分对邮件进行排序

Java 根据用户输入的最高分对邮件进行排序,java,arrays,sorting,java.util.scanner,Java,Arrays,Sorting,Java.util.scanner,我有这4个打印出来的句子,基本上希望用户为10个句子中的每一个输入一个分数,并将它们存储在数组中,然后包括一种按照分数顺序排列句子的方法,并按照从高到低的顺序打印 我是java新手,我正在努力解决这个问题,我设法在下面写了一些代码,这是我所能做的最远的。我不知道如何在数组中存储这些打印的消息。我不知道如何将分数与打印出来的信息联系起来。有人能帮忙吗/ public static void arrays() { String []noun = {"face", "eyes

我有这4个打印出来的句子,基本上希望用户为10个句子中的每一个输入一个分数,并将它们存储在数组中,然后包括一种按照分数顺序排列句子的方法,并按照从高到低的顺序打印

我是java新手,我正在努力解决这个问题,我设法在下面写了一些代码,这是我所能做的最远的。我不知道如何在数组中存储这些打印的消息。我不知道如何将分数与打印出来的信息联系起来。有人能帮忙吗/

public static void arrays()
    {

        String []noun = {"face", "eyes", "nose", "lips", "ears", "cheeks"}; //stores all the arrays for noun words
        Random random = new Random();  //to work out the new random
        int rand1 = random.nextInt(noun.length); 


        String []verb = {"enchant", "dazzle", "captivate" , "lure", "desire", "entice" }; // stores all the arrays for verb words
        Random random2 = new Random();
        int rand2 = random2.nextInt(verb.length);


        String []adjective = { "alluring", "angelic", "adoring", "appealing", "attractive", "beautiful"}; // stores all the arrays for adjectives
        Random random3 = new Random();
        int rand3 = random3.nextInt(adjective.length);

        printmessage (noun[rand1], verb[rand2], adjective[rand3]);  //to print the message that will use the arguments from the random selected words.

        getscore ();

    }

     public static void printmessage(String noun, String verb, String adjective)  //calls the arguments defined above, which will be used below, when executing the messages.
    {

        System.out.println("line 1: I would love to " + verb + " your " + adjective + " " + noun + "\n");

        System.out.println("line 2: Your are my " + adjective+ " " + noun + " .You " + verb +  " me" + "\n");

        System.out.println("line 3: you always look great in that " + adjective + " dress" + " and you " + verb +  " me with your " + noun + "\n");

        System.out.println("line 4: I get butterflies when I see your " + noun + " , you make me want to " + verb + " , in your " + adjective + " world" + "\n");
    }

    public static void getscore()
    {   
        Scanner input = new Scanner(System.in);

        for (int i=0; i<=3; i++)
        {
        JOptionPane.showInputDialog("Enter the scores for line: " + i);
        int result = input.nextInt();
        int[] scores = new int[result];
        scores[i] = input.nextInt();
        } 

    }
publicstaticvoid数组()
{
String[]noun={“脸”、“眼睛”、“鼻子”、“嘴唇”、“耳朵”、“脸颊”};//存储名词词的所有数组
Random Random=new Random();//计算新的随机数
int rand1=random.nextInt(名词长度);
String[]verb={“enchant”、“dazzle”、“captivate”、“lure”、“desire”、“Encite”};//存储动词词的所有数组
随机数2=新随机数();
int rand2=random2.nextInt(动词.长度);
String[]形容词={“诱惑”、“天使”、“崇拜”、“吸引人”、“吸引人”、“美丽”};//存储形容词的所有数组
Random Random 3=新的Random();
int rand3=random3.nextInt(形容词长度);
printmessage(名词[rand1],动词[rand2],形容词[rand3]);//打印将使用随机选择的单词中的参数的消息。
getscore();
}
publicstaticvoidprintmessage(字符串名词、字符串动词、字符串形容词)//在执行消息时调用上面定义的参数,这些参数将在下面使用。
{
System.out.println(“第1行:我想“+动词+”你的“+形容词+”+名词+”\n”);
System.out.println(“第2行:你是我的”+形容词+”+“+名词+”。你“+动词+”我“+”\n”);
System.out.println(“第3行:你总是穿着“+形容词+”衣服“+”很好看,你“+动词+”我和你的“+名词+”\n”);
System.out.println(“第4行:当我看到你的“+名词+”,你让我想“+动词+”,在你的“+形容词+”世界“+”\n”);
}
公共静态void getscore()
{   
扫描仪输入=新扫描仪(System.in);

对于(int i=0;i调用getScore和print语句,因为在打印消息之前需要score。因此,可以将带有getScore的int数组返回到main方法,如:

public static int[] getscore() {
    int[] scores = new int[3];
    //your logic to populate scores 
    return scores;
}
然后在你的主要工作中,你使用:

int count = 0;
int scores [] = getscore ();
Arrays.sort(scores);
printmessage (noun[rand1], verb[rand2], adjective[rand3], score[count++]);  //to print the message that will use the arguments from the random selected words.
在您的打印邮件中,您可以使用以下内容:

switch(score) {
    case 1://blah blah 
    break;
    //and so on
}        

您应该阅读“变量范围”,您可以在使用
random2
random3
的地方继续使用
random
。事实上,如果您继续使用同一个生成器,它将更加随机。