Witam ma taki problem z programem bo wyjścia takiego:
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 0 0 0 0
mam takie:
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
6 7 8 9 10
6 7 8 9 10
6 7 8 9 10
6 7 8 9 10
6 7 8 9 10
11 12 13 14 15
11 12 13 14 15
11 12 13 14 15
11 12 13 14 15
11 12 13 14 15
16 0 0 0 0
wydaje mi się ze vector idzie w mojej podwójnej pętli zamiast po i to po j. Ale nie jestem pewien bo kontenerów używam od nie dawna.
import java.util.Scanner;
import java.util.Vector;
public class Train {
static Scanner in = new Scanner(System.in);
static int answer= 0;
static Vector<Compartment> v = new Vector<Compartment>();
public static void show (Compartment[] compartment) {
for (int i = 0; i < compartment.length ; i++) {
System.out.println();
compartment[i].showComartment();
}
}
public static void showVector() {
for (int i = 0; i < v.size(); i++) {
System.out.println();
v.elementAt(i).showComartment();
}
}
public static void addPasarzerowie(int ilePasarzerow, int wagony) {
int count = 1;
for (int i = 0; i < wagony ; i++) {
Compartment c = new Compartment();
for (int j = 0; j < 5; j++) {
if (ilePasarzerow%5 > 0 && count <= ilePasarzerow) {
c.wagon[j] = count;
v.addElement(c);
}
else if (ilePasarzerow%5 == 0 && count <= ilePasarzerow ) {
c.wagon[j] = count;
v.addElement(c);
}
count++;
}
}
}
public static void addMorePasarzerow() {
}
public static void main(String[] args) {
int pasazerowie = 0;
int ileWagonow = 0;
do{
System.out.println();
System.out.println("podaj ile ma byc pasazeru");
pasazerowie = in.nextInt();
if (pasazerowie%5 > 0) {
System.out.println("tu");
ileWagonow = pasazerowie/5;
ileWagonow++;
}
else
ileWagonow = pasazerowie/5;
addPasarzerowie(pasazerowie, ileWagonow/*, compartments*/);
showVector();
}while (answer == 0);
}
}