Ejemplo 1
public class vector01 {
public static void main(String[] args) {
int[ ] edad = {45, 23, 11, 9};
System.out.println(» – » + edad[0] );
}
}
Ejemplo 2
public class vector02 {
public static void main(String[] args) {
int[ ] edad = {45, 23, 11, 9};
System.out.println(» – » + edad[0] );
System.out.println(» – » + edad[1] );
System.out.println(» – » + edad[2] );
System.out.println(» – » + edad[3] );
}
}
Ejemplo 3
public class vector03 {
public static void main(String[] args) {
String[ ] nombre = new String[3];
nombre[0]=»Guido»;
nombre[1]=»Rios»;
nombre[2]=»Ciaffaroni»;
System.out.println(» – » + nombre[0] );
System.out.println(» – » + nombre[1] );
System.out.println(» – » + nombre[2] );
}
}
Ejemplo 4
import java.util.Scanner;
public class vector04 {
public static void main(String[] args) {
Scanner teclado=new Scanner(System.in);
String[ ] nombre = new String[3];
System.out.println(«Ingrese String»);
nombre[0]=teclado.nextLine();
System.out.println(«Ingrese String»);
nombre[1]=teclado.nextLine();
System.out.println(«Ingrese String»);
nombre[2]=teclado.nextLine();
System.out.println(» – » + nombre[0] );
System.out.println(» – » + nombre[1] );
System.out.println(» – » + nombre[2] );
}
}
Ejemplo 5
import java.util.Scanner;
public class vector05 {
public static void main(String[] args) {
Scanner teclado=new Scanner(System.in);
String[ ] nombre = new String[5];
System.out.println(«Ingrese String»);
nombre[0]=teclado.nextLine();
System.out.println(«Ingrese String»);
nombre[1]=teclado.nextLine();
System.out.println(«Ingrese String»);
nombre[2]=teclado.nextLine();
System.out.println(«Ingrese String»);
nombre[3]=teclado.nextLine();
System.out.println(«Ingrese String»);
nombre[4]=teclado.nextLine();
for(int f=0;f<5;f++) {
System.out.println(» – » + nombre[f]);
}
}
}
Ejemplo 6
import java.util.Scanner;
public class vector06 {
public static void main(String[] args) {
Scanner teclado=new Scanner(System.in);
String[ ] nombre = new String[5];
for(int f=0;f<5;f++) {
System.out.println(«Ingrese String»);
nombre[f]=teclado.nextLine();
}
for(int f=0;f<5;f++) {
System.out.println(» – » + nombre[f]);
}
}
}
Ejemplo 7
import java.util.Scanner;
public class vector07 {
public static void main(String[] args) {
Scanner teclado=new Scanner(System.in);
System.out.println(«Ingrese la cantidad de String»);
int cantidad;
cantidad=teclado.nextInt();
String[ ] nombre = new String[cantidad];
for(int f=0;f<cantidad;f++) {
System.out.println(«Ingrese String N » + f );
nombre[f]=teclado.next();
}
for(int f=0;f<cantidad;f++) {
System.out.println(» – » + nombre[f]);
}
}
}
Ejemplo 8
import java.util.Scanner;
public class vector08 {
public static void main(String[] args) {
Scanner teclado=new Scanner(System.in);
int[ ][] mat = new int[3][5];
for(int f=0;f<3;f++) {
for(int c=0;c<5;c++) {
System.out.print(«Ingrese componente: » + f + » » + c + » ->»);
mat[f][c]=teclado.next();
}
}
for(int f=0;f<3;f++) {
for(int c=0;c<5;c++) {
System.out.print(«Componente : » + f + » » + c + » -> » + mat[f][c]);
}
}
}
}
Ejemplo 9
import java.util.Scanner;
public class vector09 {
public static void main(String[] args) {
Scanner teclado=new Scanner(System.in);
System.out.println(«Ingrese la cantidad de String»);
int cantidad;
cantidad=teclado.nextInt();
String[ ] nombre = new String[cantidad];
System.out.println(«Ingrese String N » + nombre.length );
for(int f=0;f<nombre.length;f++) {
System.out.println(«Ingrese String N » + f );
nombre[f]=teclado.next();
}
System.out.println(» String 0 » + nombre[0]);
System.out.println(» String 1 » + nombre[1]);
System.out.println(» String 2 » + nombre[2]);
System.out.println(» String 3 » + nombre[3]);
Ejemplo
import java.util.Scanner;
public class ejemplo {
public static void main(String[] args) {
Scanner teclado=new Scanner(System.in);
/****************************************************/
System.out.println(«Ingrese la cantidad de Alumnos»);
int cantidad;
cantidad=teclado.nextInt();
/****************************************************/
/****************************************************/
String[ ] nombre = new String[cantidad];
String[ ] apellidop = new String[cantidad];
String[ ] apellidom = new String[cantidad];
/****************************************************/
/****************************************************/
for(int f=0;f<cantidad;f++) {
System.out.println(«Ingrese el nombre del alumno » );
nombre[f]=teclado.next();
System.out.println(«Ingrese el apellido paterno del alumno » );
apellidop[f]=teclado.next();
System.out.println(«Ingrese el apellido materno del alumno » );
apellidom[f]=teclado.next();
}
/****************************************************/
/****************************************************/
for(int f=0;f<cantidad;f++) {
System.out.println(«Alumno : » + nombre[f] + » » + apellidop[f] + » » + apellidom[f] );
}
/****************************************************/