1. PONTIFICIA UNIVERSIDAD CATÓLICA DEL ECUADOR SEDE IBARRA
ESCUELA DE INGENIERIA
CARRERA DE SISTEMAS
NOMBRE: Grace Laguna FECHA: 09-04-2013
NIVEL: Quinto
COMPILACIÓN CON DOS
1. Con la ayuda del cmd compilamos el programa.
2. Al ser compilado correctamente se crea un archivo .class
2. 3. Aquí tenemos la pantalla del programa ejecutándose correctamente
Código del programa:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package arreglos2;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/**
*
* @author GRACE
*/
public class Arreglos2 {
/**
* @param args the command line arguments
3. */
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Ingrese n: ");
int n = Integer.parseInt(br.readLine());
int vector[] = new int[n];
for (int i = 0; i < n; i++)
{
System.out.print("Ingrese el valor en la posicion "+i+": ");
vector[i] = Integer.parseInt(br.readLine());
}
int aux;
if(n%2==0)
{
for (int i = 0; i < (n/2); i++)
{
for (int j = i; j < (n/2); j++)
{
if(vector[i]>vector[j]){
aux = vector[i];
vector[i]=vector[j];
vector[j]=aux;
}
}
}
for (int i = (n/2); i < n; i++)
{
for (int j = i; j < n; j++)
{
if(vector[i]<vector[j])
{
aux = vector[i];
vector[i]=vector[j];
vector[j]=aux;
}
}
}
}
else
{
4. for (int i = 0; i < n; i++)
{
for (int j = i; j < n; j++)
{
if(vector[i]>vector[j])
{
aux = vector[i];
vector[i]=vector[j];
vector[j]=aux;
}
}
}
}
for (int i = 0; i < n; i++)
{
System.out.print(vector[i]+",");
}
}
}