public static void displayArray(int tab[]){
int i;
String choix; // choice
System.out.println("\n you want to see the values you entred from first position or last ?");
System.out.println("tape "P" for first , and"D" for last);
choix=sc1.nextLine(); // sc1 for nextLine , sc for nextInt to avoid buffering problems .
if(choix=="p"||choix=="P")
{ for(i=0;i<k;i++) //k is the maximum of the array(max index)
System.out.println("T["+i+"]= "+tab[i]); // why this instruction doesn't work ??
}
if(choix=="D"||choix=="d")
{for(i=k-1;i>=0;i--)
System.out.println("T["+i+"]= "+tab[i]);// this one too doesn't work
}}
public static void main(String[] args) {
// TODO Auto-generated method;stub
int tab[]=new int[4];
System.out.println(readIntArray(tab));
displayArray(tab);
}
}
Я не понимаю, почему displayArray
не работает, System.out.println
должен напечатать мой массив после проверки состояния, но он не работает.Почему Println не показывает мой массив
Ваш код не работает, так как некорректная печать: 'System.out.println (« лента «P» для первого и «D» для последнего »);' – naurel
'// k - это максимум массива (max index) '... Хорошо, так где вы установили' k'? – Mariano