soumiaMoufid's blog

By soumiaMoufid, history, 7 years ago, In English

please i got "rutime error on test 1" with this code any help?? thanks in advance

package graph.party;

import java.util.ArrayList;
import java.util.Scanner;

public class Party2 {

	public Party2() {
		Scanner in = new Scanner(System.in);
		System.out.println("entrez le nombre des employés\n");
		int n = in.nextInt();
		ArrayList<Integer> tab=new ArrayList<Integer>(n);
		for(int i=0;i<n;i++){
			tab.add(in.nextInt());
		}
		int result=0;
		for(int j=0;j<n;j++){
			int temp=1;int var=tab.get(j);
			while(var != -1){var=tab.get(var-1);temp++;}
			if(temp>result) result=temp;
		}
		System.out.println(result);
	}

	public static void main(String[] args) {
		new Party2();

	}

}

  • Vote: I like it
  • +3
  • Vote: I do not like it

»
7 years ago, # |
Rev. 3   Vote: I like it +13 Vote: I do not like it

Delete package graph.party;, as well as System.out.println("entrez le nombre des employés\n");, they are not necessary.