Wyświetlanie elementu tablicy
Tablica jest jednowymiarowa – czteroelementowa, zaprogramowane w kodzie. Program z kolei wyświetla wartość elementu tablicy.
Kompilator: Eclipse
import javax.swing.JOptionPane;
public class glowna {
//Program wyświetlający element tablicy.
public static void main(String[] args) {
int tab[]=new int[]{1,2,3,4};
try{
int x= Integer.parseInt(JOptionPane.showInputDialog("Który element wyświetlić: "));
System.out.print(tab[x-1]);
}catch(Exception e){
System.out.print("Wyszedłeś poza tablicę.");}
}
}