This question already has an answer here:
- int[] array (sort lowest to highest) 10 answers
I have a project in school to make a simplified Yatzy program and now i've hit a road bump. I have generated 5 random dice throws and printed them out in one window but i need to sort them from lowest to highest and i dont know how. Ive looked in forums like this one but i dont understand, feel free to ask questions if you dont understand. Btw im swedish so the text in the "" lines are in swedish if u dont understand This is my code: import javax.swing.*;
public class Projekt1 {
public static void main(String[] args) {
JOptionPane.showMessageDialog(null, "Välkommen till Johans Yatzy");
JOptionPane.showConfirmDialog(null, "Vill du starta spelet?");
int[] tar = new int[5];
String output = "";
for(int i=0; i<5; i++){
tar[i] = (int)(Math.random()*6+1);
output = output + tar[i] + "\t";
}
JOptionPane.showMessageDialog(null, "Dina tärningskast blev följande: " + output);
}
}
Aucun commentaire:
Enregistrer un commentaire