Vous êtes sur la page 1sur 54

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013

PROGRAMA 1:
BIENVENIDO1------------------------------------------------------------------------------------------------------------------------------MUESTRA E IMPRIME EN PANTALLA TEXTO O MENSAJE DE BIENVENIDA POR MEDIO DEL METODO PRINTLN:
// Fig. 2.1: Bienvenido1.java
// Programa para imprimir texto.
// Flavio Ramos Zetina.
// 09 Octubre 12.
public class Bienvenido1
{
// el metodo main empieza la ejecucion de aplicacion en Java
public static void main( String args[] )
{
System.out.println( "Bienvenido a la programacion en Java!");
} // fin del metodo main
} // fin de la clase Bienvenido1
PROGRAMA 2:-----------------------------------------------------------------------------------------------------------------------------IMPRIME EN PANTALLA Y MUESTRA UN TEXTO PORMEDIO DE LA COMBINACION DE METODO PRINT Y
PRINTLN:
// Fig. 2.3: Bienvenido2.java
// Imprimir una linea de texto con varias instrucciones.
// Flavio Ramos Zetina.
// 09 Octubre 12.
public class Bienvenido2
{
// el metodo main empieza la ejecucion de la aplicacion en Java
public static void main(String args[])
{
LIC.FLAVIO RAMOS ZETINA

Pgina 1

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


System.out.print( "Bienvenido a ");
System.out.println( "la programacion en Java " );
} // fin del meto main
} // fin de la Clase Bienvenido2
PROGRAMA 3:-----------------------------------------------------------------------------------------------------------------------------IMPRIME VARIAS LINEAS DE TEXTO EN UNA SOLA INSTRUCCIN POR MEDIO DEL METODO PRINTLN:
// Fig. 2.4: Bienvenido3.java
// Imprimir varias lineas de texto con una sola instrucion.
// Flavio Ramos Zetina.
// 09 Octubre 12.
public class Bienvenido3
{
// el metodo main empieza la ejecucion de la aplicacion en Java
public static void main(String args[])
{
System.out.println("Bienvenido\na\nla Programacion\nen Java");
} // fin del emtodo main
} // fin de la clase bienvenido3
PROGRAMA 4:-----------------------------------------------------------------------------------------------------------------------------IMPRIME UNA COMBINACION DE LINEA DE TEXTO POR MEDIO DEL METODO PRINTF:
// Fig. 2.6: Bienvenido4.Java
// Imprimir varias lineas en dialogo de texto.
// Flavio Ramos Zetina.
// 09 Octubre 12.
public class Bienvenido4
{
LIC.FLAVIO RAMOS ZETINA

Pgina 2

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


// el metodo main empieza la ejecucion de la aplicacion en Java
public static void main(String args[])
{
System.out.printf( "%s\n%s\n" ,
"Bienvenido a" , "la programacion en Java!");
} // fin del metodo main
} // fin de la clase Bienvenido4
PROGRAMA 5:-----------------------------------------------------------------------------------------------------------------------------IMPRIME DOS LINEAS DE TEXTO POR MEDIO DE LA COMBINACION \n CON EL METODO PRINTLN:
// la clase Bienvenido.Java
// Flavio Ramos Zetina.
// 09 Octubre 12
public class Bienvenido5
{
// el metodo main empieza la ejecucion de la aplicaion en Java
public static void main(String args[])
{
// imprimir soy cabron para ejecutar Java
System.out.println("Soy Cabron\n para Ejecutar Java!");
} // fin del metodo main
} // fin de la clase Bienvenido5
PROGRAMA 6:-----------------------------------------------------------------------------------------------------------------------------ANATOMIA
IMPRIME UNA LINA DE TEXTO POR MEDIO DEL String QUE LO EJECUTA EL METODO PRINTLN:
class Anatomia {
public static void main( String[]args ) {
LIC.FLAVIO RAMOS ZETINA

Pgina 3

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


String saludo = "Bienvenido al Curso de Video Tutoriales de Java!";
System.out.println( saludo );
} // fin del metodo main
} // fin de class Anatomia

PROGRAMA 7:-----------------------------------------------------------------------------------------------------------------------------IMPRIME TRES TIPOS DE ARGUMENTOS POR MEDIO DEL METODO PRINTLN:
// imprime tres tipos de argumentos.
// Flavio Ramos Zetina.
// 12 Octubre 12.
// class ConArgumentos1.java
public class ConArgumentos1
{
// empieza la ejecusion del metodo main para la progamacion en java
public static void main(String args[])
{
System.out.println(" Los lenguajes de programacion que prefiero son: "
+ " El primero: " + args[0]
+ " El segundo: " + args[1]
+ " Y por ultimo el tercero es: " + args[2] );
} // Fin del metodo main
} // Fin de la clase java
PROGRAMA 8:-----------------------------------------------------------------------------------------------------------------------------IMPRIME LA RAIZ CUADRADA DE UN NUMERO POR MEDIO DE APPLET EN UNA VENTANA:
import java. awt. *;
public class EjemploApplet extends javax.swing.JApplet {
LIC.FLAVIO RAMOS ZETINA

Pgina 4

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


int numero;
public void init() {
numero = 317;
} // Fin de void
public void paint(Graphics screen){
Graphics screen2D = (Graphics) screen;
screen2D. drawString("La raiz cuadrada de " +
numero +
" es: " +
Math.sqrt(numero), 5, 50);
}// Fin de void paint
} // Fin de la clase EjemploApplet
PROGRAMA 9: ----------------------------------------------------------------------------------------------------------------------------IMPRIME LA RAIZ CUADRADA DE UN NUMERO POR MEDIO DE INT Y EL METODO PRINTLN
class Operacion {
public static void main(String[]args) {
int numero = 357;
System.out.println("La raiz cuadrada de"
+numero
+" es "
+Math.sqrt( numero );
}
}
PROGRAMA 10:---------------------------------------------------------------------------------------------------------------------------IMPRIME RESIDUO DE UNA OPERACION POR MEDIO DE FLOAT EJECUTADO MEDIANTE EL METODO:
class Operaciones {
LIC.FLAVIO RAMOS ZETINA

Pgina 5

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


public static void main(String[] args){
float altura = 123;
altura = altura%7;
System.out.println( altura );
}
}

PROGRAMA 11:---------------------------------------------------------------------------------------------------------------------------PIDE AL USUARIO UN NUMERO POR MEDIO DEL TACLADO EJECUTADO POR UN Scanner:
import java.util.Scanner;
class YadiraYazmin{
public static void main(String args[]){
Scanner entrada= new Scanner( System.in);
int A; // la primera suma
int B; // la segunda suma
int suma; //el ejecutor

// Desde aqui pide al usuario las entradas


System.out.println( "Dame la suma 1" );
A = entrada.nextInt(); // pide al usuario la suma de A
System.out.println( "Dame la suma 2" ); // pide al usuario la suma B
B = entrada.nextInt();

suma = A + B; // Ejecuta la suma


// Muestra la suma por medio del metodo println
System.out.println( suma );
LIC.FLAVIO RAMOS ZETINA

Pgina 6

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


System.out.println( "Gracias por su preferencia" );
} //fin del metodo main
} //fin de la clase YadiraYazmin
PROGRAMA 12:---------------------------------------------------------------------------------------------------------------------------SE USA UN CANTADOR Y UN ARREGLO
ARREGLOS 7
// fig 7.2:
// Creacion de un arreglo
class Arreglo {
public static void main( String[]args ) {
int arreglo[]; // Declara un arreglo con el mismo nombre.

arreglo = new int[ 10 ]; // Crea el espacio para el arreglo.

System.out.printf( "%s%8s\n", "indice", "valor" ); // Encabezado de columnas.

// imprime el valor de cada elemento del arreglo.


for( int contador = 0; contador<arreglo.length; contador++ )
System.out.printf( "%6d%8d\n", contador, arreglo[ contador++ ] );
} // fin de main
} // fin de arreglo
PROGRAMA 13:---------------------------------------------------------------------------------------------------------------------------PIDE AL USUARIO INTRODUSCA UN NUMERO POR MEDIO DEL METODO Scanner:
import java.util.Scanner;
public class Ejercicio710 {
public static void main(String[]args){
LIC.FLAVIO RAMOS ZETINA

Pgina 7

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


int b=200,c=300,d=400,e=500,f=600,g=700,h=800,i=900,j=1000;
Scanner in = new Scanner(System.in);
int trab, ventas,comision,sueldo;
System.out.println("Introduzca el numero de trabajadores");
trab=in.nextInt();
int sueldos[]=new int[trab];
int cantidad[]=new int[10];

for(int cont=0;cont<trab;cont++){
System.out.println("Cuanto vendio el trabajdor: ");
ventas=in.nextInt();
comision = (int) ((int)ventas*.09);
sueldo = 200+comision;
sueldos[cont]=sueldo;
}
String[] etiqueta = {"0","200-299","300-399","400-499","500-599","600-699","700-799","800899","900-999","1000+"};
int FC[] = new int [10];
for(int frecuencia=0;frecuencia<sueldos.length;frecuencia++){
if(sueldos[frecuencia]>b&&sueldos[frecuencia]<c){
++FC[1];}
if(sueldos[frecuencia]>c && sueldos[frecuencia]<d){
++FC[2];}
if(sueldos[frecuencia]>d && sueldos[frecuencia]<e){
++FC[3];}
if(sueldos[frecuencia]>e && sueldos[frecuencia]<f){
++FC[4];}
LIC.FLAVIO RAMOS ZETINA

Pgina 8

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


if(sueldos[frecuencia]>f && sueldos[frecuencia]<g){
++FC[5];}
if(sueldos[frecuencia]>g && sueldos[frecuencia]<h){
++FC[6];}
if(sueldos[frecuencia]>h && sueldos[frecuencia]<i){
++FC[7];}
if(sueldos[frecuencia]>i && sueldos[frecuencia]<j){
++FC[8];}
if(sueldos[frecuencia]>j){
++FC[9]
}
System.out.println("Sueldo\tFrecuencia");
for(int y= 1;y<FC.length;y++){
System.out.printf(etiqueta[y]);
System.out.printf("\t%d\n",FC[y])
}
}
}

PROGRAMA 14: ANALIZA EL PROGRAMA:------------------------------------------------------------------------------------------

public class Elemento1 {


public static void main( String[]args ) {
int arreglo[]= { 32, 27, 64, 18, 95, 14, 90, 70, 60, 37 };
System.out.printf( "%s%8s\n", "vector", "valor n" ); // Encabezado de columnas.

LIC.FLAVIO RAMOS ZETINA

Pgina 9

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


// imprime el valor de cada elemento del arreglo.
for( int contador = 0; contador<arreglo.length; contador++ )
System.out.printf( "%5d%8d\n", contador, arreglo[ contador++ ] );
int total= 0;
// Suma el valor de cada elemento al total
for( int contador = 0; contador<arreglo.length; contador++ )
total += arreglo[ contador ];
System.out.printf( "Total de los elementos del arreglo: %d\n", total );

} // fin de main
} // fin de la clase Elemento1
PROGRAMA 15: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------//fig 7.8: EncuestaEtudiante.java
//programa de analisis de una encuesta.

public class EncuestaEstudiante {


public static void main( String[]args ) {

//Arreglo a una encuesta


int respuestas[] = { 1, 2, 4, 8, 5, 9, 7, 8, 10, 1, 6, 3, 8, 6,
10, 3, 8, 2, 7, 6, 5, 7, 6, 8, 6, 7, 5, 6, 6, 5, 6, 7, 5, 6,
4, 8, 6, 8, 10};
int frecuencia[] = new int[ 11 ]; //arreglo de contadores de frecuencia

// para cada respuesta, selecciona el elemento de respuestas y usa ese valor


// como indice de frecuencia para determinar el elemento a incrementar
LIC.FLAVIO RAMOS ZETINA

Pgina 10

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


for( int respuesta = 0; respuesta < respuestas.length; respuesta++)
++frecuencia[ respuestas[ respuesta ] ];

System.out.printf( "%s%12s\n", "Calificacion", "Frecuencia" );

// imprime el valor de cada elemento del arreglo


for( int calificacion = 1; calificacion < frecuencia.length; calificacion++ )
System.out.printf("%12d%12d\n", calificacion, frecuencia[ calificacion] );

} // fin de la clase main


} // fin de la clase EncuestaEstudiante

PROGRAMA 16: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------// fig 7.6


// Programa para imprimir graficos de barras
public class GraficoBarras {
public static void main(String args[]){
int arreglo[]= { 0, 0, 0, 0, 0, 0, 1, 2, 4, 2, 1};
System.out.println(" Distribusion de Calificaciones:");
// Para cada elemento del arreglo, imprime una barra del grafico
for( int contador = 0; contador<arreglo.length; contador++ )
{
// imprime etiqueta de barra ( "00-09", ..., "90-99", "100: " )
if( contador == 10 )
System.out.printf("%5d: ", 100);
else
LIC.FLAVIO RAMOS ZETINA

Pgina 11

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


System.out.printf("%02d-%02d:",
contador * 10, contador * 10 + 9);

// imprime barra de asteriscos


for( int estrellas = 0; estrellas < arreglo[ contador ]; estrellas++)
System.out.printf( "*" );

System.out.println(); // inicia una nueva linea de salida


} // fin de for externo
} // fin del metodo main

} // fin de la clase GraficoBarra

PROGRAMA 17: ANALIZA EL PROGAMA--------------------------------------------------------------------------------------------// fig 7.4:


// Calculo de los valores acolocar en los elementos de un arreglo
public class InicArreglo2 {
public static void main( String[]args ) {
final int LONGITUD_ARREGLO= 10; // Declara la constante
int arreglo[]= new int[ LONGITUD_ARREGLO ]; // Crea el arreglo

// Calcula el valor para cada elemento del arreglo


for( int contador = 0; contador<arreglo.length; contador++ )
arreglo[ contador ] = 2 + 2 * contador;
System.out.printf( "%s%8s\n", "indice", "valor" ); // Encabezado de columnas.
// imprime el valor de cada elemento del arreglo.
LIC.FLAVIO RAMOS ZETINA

Pgina 12

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


for( int contador = 0; contador<arreglo.length; contador++ )
System.out.printf( "%6d%8d\n", contador, arreglo[ contador++ ] );
} // fin de main
} // fin de Inicarreglo2
PROGRAMA 18: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------// fig.7.5:
// Calculo de la suma de los elementos de un arreglo.
public class SumaArreglo {
public static void main( String[]args ) {
int arreglo[]= { 87, 68, 94, 100, 83, 78, 85, 91, 76, 87};
int total= 0;
// Suma el valor de cada elemento al total
for( int contador = 0; contador<arreglo.length; contador++ )
total += arreglo[ contador ];
System.out.printf( "Total de los elementos del arreglo: %d\n", total );
} // fin de main
} // fin de la clase sumaarreglo
PROGRAMA 19: ANALIZA EL PROGRAMA:-------------------------------------------------------------------------------------//fig 7.7: TirarDado.java
// Tira un dado de seis lados 6000 veces.
import java.util.Random;

public class TirarDado {


public static void main(String args []) {
Random numerosAleatorios = new Random(); //Generador de numeros aleatorios
int frecuencia[] = new int[ 7 ]; //Arreglos de contadores de frecuencia
LIC.FLAVIO RAMOS ZETINA

Pgina 13

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


//Tira el lado 6000 veces; usa el valor del lado como indice de frecuencia
for( int tiro = 1; tiro <= 6000; tiro++ )
++frecuencia[ 1 + numerosAleatorios.nextInt( 6 )];

System.out.printf( "%s%10s\n", "Cara", "Frecuencia" );

for( int cara = 1; cara < frecuencia.length; cara++ )


System.out.printf("%4d%10d\n", cara, frecuencia[ cara ] );
}// fin del metodo main
}// fin de de la clase TirarDado
PROGRAMA 20: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------COMPRUEBA
public class ConPrueba {
public static void main(String args[]){
int numero1= 0;
int numero2= 0;
int numero3= -3;
int numero4= -3;
int numero5= 6;

if( numero1==numero2)
System.out.printf("Hay dos Numeros:%d\n", numero1, numero2);
if( numero3==numero4)
System.out.printf("Hay dos Numeros Negativos:%d\n", numero3, numero4);
if( numero5==numero5)
LIC.FLAVIO RAMOS ZETINA

Pgina 14

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


System.out.printf("Hay Solo un numero Positivo:%d\n", numero5, numero5);
}
}

PROGRAMA 21: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------public class Dias {


public enum DiaSemana{LUNES, MARTES, MIERCOLES, JUEVES, VIERNES, SABADO, DOMINGO}
public static void main(String args[]){
DiaSemana hoy = DiaSemana.JUEVES;
DiaSemana ultimo = DiaSemana.DOMINGO;
System.out.println( "Hoy es:" + hoy );
System.out.println( "El ultimo dia es:" + ultimo );
}
}
PROGRAMA 22: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------public class Elemento1 {
public static void main(String args[]){
String vienBenida= "\"Vienvenidos a Este Rompecabezas\"";
System.out.println(vienBenida);

int contador;
for (contador = 1; contador<=15; contador++){
System.out.println(contador);
}

int []arregloPrimero = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};


LIC.FLAVIO RAMOS ZETINA

Pgina 15

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


System.out.println("Arreglos "+arregloPrimero.length+" y no mas Pero Estabien");

int raiz= 15;


System.out.println("La raiz Cuadrada de 15 es: " + Math.sqrt(raiz));

int total= 15;


int suma = total + 15 * (20 / 7);
System.out.println("Este Combinado logico es:" +suma);
int[] numeros = null;
}
}

PROGRAMA 23: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------import java.util.Scanner;


public class Reflejo {
public static void main( String args[] ){

int tabla;
Scanner reader = new Scanner(System.in);
System.out.print("Que Tabla de Multiplicar Deceas Revisar?");
tabla = reader.nextInt();

System.out.println("****TABLA DE MULTIPLICAR GENERADA****");


for( int var1 = 1; var1 < 11; var1++ )
System.out.println( "Multiplicacion de:" + tabla + "x" + var1 + "=" +( var1*tabla ) );
LIC.FLAVIO RAMOS ZETINA

Pgina 16

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


}
}
PROGRAMA 24: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------TABLAS BOOLEANAS
import javax.swing.*;
public class Ventas {

public static void main( String args[] )


{
// create JTextArea to display results
JTextArea outputArea = new JTextArea( 17, 20 );
// attach JTextArea to a JScrollPane so user can scroll results
JScrollPane scroller = new JScrollPane( outputArea );

// create truth table for && (conditional AND) operator


String output = "Conditional AND (&&)" +
"\nfalse && false: " + ( false && false ) +
"\nfalse && true: " + ( false && true ) +
"\ntrue && false: " + ( true && false ) +
"\ntrue && true: " + ( true && true );

// create truth table for || (conditional OR) operator


output += "\n\nConditional OR (||)" +
"\nfalse || false: " + ( false || false ) +
"\nfalse || true: " + ( false || true ) +
"\ntrue || false: " + ( true || false ) +
LIC.FLAVIO RAMOS ZETINA

Pgina 17

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


"\ntrue || true: " + ( true || true );

// create truth table for & (boolean logical AND) operator


output += "\n\nBoolean logical AND (&)" +
"\nfalse & false: " + ( false & false ) +
"\nfalse & true: " + ( false & true ) +
"\ntrue & false: " + ( true & false ) +
"\ntrue & true: " + ( true & true );

// create truth table for | (boolean logical inclusive OR) operator


output += "\n\nBoolean logical inclusive OR (|)" +
"\nfalse | false: " + ( false | false ) +
"\nfalse | true: " + ( false | true ) +
"\ntrue | false: " + ( true | false ) +
"\ntrue | true: " + ( true | true );

// create truth table for ^ (boolean logical exclusive OR) operator


output += "\n\nBoolean logical exclusive OR (^)" +
"\nfalse ^ false: " + ( false ^ false ) +
"\nfalse ^ true: " + ( false ^ true ) +
"\ntrue ^ false: " + ( true ^ false ) +
"\ntrue ^ true: " + ( true ^ true );

// create truth table for ! (logical negation) operator


output += "\n\nLogical NOT (!)" +
"\n!false: " + ( !false ) +
LIC.FLAVIO RAMOS ZETINA

Pgina 18

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


"\n!true: " + ( !true );

outputArea.setText( output ); // place results in JTextArea

JOptionPane.showMessageDialog( null, scroller,


"Truth Tables", JOptionPane.INFORMATION_MESSAGE );

System.exit( 0 ); // terminate application


} // end main
} // end class LogicalOperators
PROGRAMA 25: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------SICLOFOR
// 4.25 ejercicio CalificacionEstudiante.java
// las instrucciones if...else
public class CalificacionEstudiante {
public static void main(String args[]) {
int CalificacionEstudiante = 90;

if (CalificacionEstudiante >= 60)


System.out.println("Aprovado");
else
System.out.println("Reprovado");

} // fin del metodo main


} // fin de la clase CalificacionEstudiante
PROGRAMA 26: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------LIC.FLAVIO RAMOS ZETINA

Pgina 19

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


// Fig. 5.1: ContadorWhile.java
// repeticion controlada con contador, con la instruccion de repeticion while
public class ContadorWhile {
public static void main(String args[]) {
int contador= 1;
while (contador <= 10) // condicion de continuacion de siclo
{
System.out.printf("%d ", contador);
++contador;

// incrementa la variable de control

} // fin de while
System.out.println();
} // fin del metodo main
} // fin de la clase ContadorWhile
PROGRAMA 27: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------public class Descuento {
public static void main(String args[]) {
int Descuento =1010;
if ( Descuento >= 1000)
System.out.println("mayor");
else
System.out.println("menor");

} // fin del metodo main


} // fin de la clase Descuento
PROGRAMA 28: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------// 4.25 ejercicio Misterio2.java
LIC.FLAVIO RAMOS ZETINA

Pgina 20

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


// instruccion while
public class Misterio2 {
public static void main(String args[]) {
int cuenta = 1;
while ( cuenta <= 10) {
System.out.println(cuenta % 2 == 1 ? "****" : "++++++++");
++cuenta;
} // fin de while
} // fin de la clase main
} // fin de la clase Misterio2
PROGRAMA 29: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------// 4.26 ejercicio Misterio3.java
// instrucciones while
public class Misterio3 {
public static void main(String args[]) {
int fila = 10;
int columna;

while ( fila >= 1) {


columna = 1;

while ( columna <= 10 ) {


System.out.print( fila % 2 == 1 ? "<" : ">");
++columna;
} // fin de while
--fila;
LIC.FLAVIO RAMOS ZETINA

Pgina 21

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


System.out.println();
} // fin de while
} // fin de la clase main
} // fin de la clase main
PROGRAMA 30: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------import java.util.Scanner;
public class Producto {
public static void main(String args[]) {
Scanner entrada = new Scanner (System.in);
int x;
int y
int z;
int resultado;
System.out.print("Escriba el primer entero: ");
x= entrada.nextInt();

System.out.print("Escriba el segundo entero: ");


y= entrada.nextInt();

System.out.print("Escriba el tercer entero: ");


z= entrada.nextInt();

resultado= x *y * z;

System.out.printf("El producto es %d\n", resultado);

LIC.FLAVIO RAMOS ZETINA

Pgina 22

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


if ( x != y)
System.out.println( "Objetivo Bien hecho" );
else
{
System.out.println( "Ok de todos mados" );
} // fin de else
} // fin del metodo main
} // fin de la clase Producto
PROGRAMA 31: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------// figura 5.7: PruebaDowhile.java
// las instrucciones de repeticion do...while.
public class PruebaDowhile {
public static void main(String args[]) {
int contador = 1; // inicializa contador
do
{
System.out.printf( "%d ", contador);
++contador;
} while ( contador <= 10); // fin de do...while
System.out.println(); // Ejecuta una nueva linea
} // fin del metodo main
} // fin de la clase PruebaDowhile
PROGRAMA 32: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------public class PruebaWhile {
public static void main(String args[]) {
System.out.printf("%s\t%s\t%s\t%s\n","N","N*10","100*N","1000*N");
LIC.FLAVIO RAMOS ZETINA

Pgina 23

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


int n= 1;
while ( n <= 5) {
System.out.printf("%d\t%d\t%d\t%d\n",
n,10*n,100*n,1000*n);
++n;
}
} // fin del metodo main
} // fin de la clase PruebaWhile

PROGRAMA 33: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------public class TablaDowhile {


public static void main(String args[]) {
System.out.printf("%s\t%s\t%s\t%s\n","N","N*10","100*N","1000*N");
int n= 1;
do {
System.out.printf("%d\t%d\t%d\t%d\n",
n,10*n,100*n,1000*n);
++n;
} while(n<=5);
} // fin del metodo main
} // fin de la clase TablaDowhile
PROGRAMA 34: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------SUMA1
// muestra las figuras
public class SumFigura {
public static void main( String args[] ) {
LIC.FLAVIO RAMOS ZETINA

Pgina 24

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


System.out.printf("%s\n%s\n%s\n", "**** ***
"**** ***

*", "* * * * ***",

*");

}
}
PROGRAMA 35: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------// class TexConArgumentos.java
//Flavio Ramos Zetina.
public class TexConArgumentos { // el metodo main comienza aqui.
public static void main(String args[]){
// System se ejecutara aqui.
System.out.println("Imprime los dos siguientes enteros"
+ " El primero:" + args[0]
+ " El segundo:" + args[1]
+ " y por ultimo el tercero es:" + args[2] );
} // fin del metodo main
} // fin del la clase TexConArgumentos
PROGRAMA 36: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------TextoMix
// clase Texprintf.java
// Flavio Ramos Zetina.
// imprimir varias lineas.
public class Texprintf {
// el metodo main comiensa aqui.
public static void main(String args[]){
// imprime printf
System.out.printf("%s\n%s\n" ,
LIC.FLAVIO RAMOS ZETINA

Pgina 25

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


"la clase Java" , "Comienza a qui!");
} // fin de la clase main
} // fin de la clase Texprintf
PROGRAMA 37: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------// clase TextoMix.java
// imprime textos con diferente con binacion.
// Flavio Ramos Zetina.
public class TextoMix {
// la clase main comienza a qui.
public static void main(String[] args){
// imprime una sola linea con diferente conbinacion.
// por medio de print y println.
// Imprime Texto con Diferente Conbinacion.
System.out.print("\"Imprime\tTexto\"");
System.out.println(" con\\diferente\n Conbinacion!");
} // fin de main
} // fin de la clase TextoMix.
PROGRAMA 38: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------VIDEO 5:
class Incremento {
public static void main(String args[]) {
int x = 3;
int valor = ++x * 10;
System.out.println( valor );
System.out.println( x );
} // fin del metodo main
LIC.FLAVIO RAMOS ZETINA

Pgina 26

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


} // fin de la clase Operadores
PROGRAMA 39: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------class Operadores {
public static void main(String args[]) {
float altura = 123;
altura = altura % 7;
System.out.println( altura );
} // fin del metodo main
}// fin de la clase Operadores
PROGRAMA 40: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------class OperadoresMas {
public static void main(String args[]) {
int puntuacion = 12;
int total = 325 + ( puntuacion * 22 );
System.out.println( total );
} // fin del metodo main
} // fin de la clase Operadores
PROGRAMA 41: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------class PesoPlaneta {
public static void main(String args[]) {
System.out.print( "Tu peso en la Tierra es de:" );
double peso = 72;
System.out.println( peso );

System.out.print( "Tu peso en mercurio es de:" );


double mercurio = peso * .378;
LIC.FLAVIO RAMOS ZETINA

Pgina 27

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


System.out.println( mercurio );

System.out.print( "Tu peso en la luna es de:" );


double luna = peso * .166;
System.out.println( luna );
System.out.print( "Tu peso en jupiter es de:" );
double jupiter = peso * 2.364;
System.out.println( jupiter );
} // fin del metodo main
} // fin de la clase PesoPlaneta
PROGRAMA 42: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------class Prioridad {
public static void main(String args[]) {
int y = 21;
int x = y * 3 + 5;
System.out.println( x );
} // fin del metodo main
} // fin de la clase Prioridad2
PROGRAMA 43: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------class Prioridad2 {
public static void main(String args[]) {
int x = 7;
int z = x++ * 6 + 4 * 10 / 2;
System.out.println( z );
System.out.println( x );
} // fin del metodo main
LIC.FLAVIO RAMOS ZETINA

Pgina 28

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


}// fin de la clase Prioridad2
PROGRAMA 44: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------class Prioridad3 {
public static void main(String args[]) {
int y = 21;
int x = y *( 3 + 5 );
System.out.println( x );
} // fin del metodo main
} // fin de la clase Prioridad3

PROGRAMA 45: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------public class Tiempo {


public static void main( String[]arguments ) {
float fah = 86;
System.out.println( fah + "grados Fahrenheit son ..." );
// Para convertir Fahrenheit a celsius
// Enpezamos por restar 32
fah = fah - 32;
// Dividimos el resultado por 9
fah = fah / 9;
// Multiplicamos el resultado por 5
fah = fah * 5;
System.out.println( fah + "grados Celsius son\n" );
float cel = 33;
System.out.println( fah + "grados Celsius son ..." );
LIC.FLAVIO RAMOS ZETINA

Pgina 29

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


// Para convertir Fahrenheit a celsius
// Empezamos por restar 9
cel = cel * 9;
// Dividimos el resultado por 5
cel = cel / 5;
// Aadimos 32 al resultado
cel = cel + 32;
System.out.println( cel + "grados Celsius son" );
} // fn del metodo main
} // fin de la clase Tiempo
PROGRAMA 46: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------VIDEO6
class CaracteresEspeciales {
public static void main(String[] args) {
System.out.println("La mejor cancion de victor jara es \"terecuerdo amanda\"");
} // fin del metodo main
} // fin de la clase MostrarMensaje
PRGRAMA 47: ANALIZA EL PROGRAMA:-------------------------------------------------------------------------------------------class Case {
public static void main(String[ ] args) {
String nombre = "Pedro Gonzlez";
String minusculas = nombre.toLowerCase();
String mayusculas = nombre.toUpperCase();
System.out.println( minusculas );
System.out.println( mayusculas );
}
LIC.FLAVIO RAMOS ZETINA

Pgina 30

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


}
PROGRAMA 48: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------class ConcatenacionVariable {
public static void main(String[] args) {
int numero =143;
char valor='M';
System.out.println("Hubo un total de:" + numero + " particpantes");
System.out.println("promedio " + valor);
} // fin del metodo main
} // fin de la clase ConcatenacionVariable

PROGRAMA 49: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------class Concatenacion {


public static void main(String[] args) {
System.out.println("\"\'Descubrir\' el verdadero viaje de descubrimiento consiste" +
"no encontrar nuevas tierras si no, varias con nuevos ojos.\"\'\n\t-- Marcel proust, citas");
} // fin del metodo main
} // fin de la clase MostrarMensaje

PROGRAMA 50: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------class IndexOf {


public static void main(String[ ] args) {
String texto = "Seguale Sancho a todo trote de su jumento; pero caminaba tanto Rocinante, que, vindose
quedar atrs, le fue forzoso dar voces a su amo, que se aguardase.";
LIC.FLAVIO RAMOS ZETINA

Pgina 31

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


int busca = texto.indexOf( "Sancho" );
System.out.println( busca );
}
}
PROGRAMA 51: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------class MostrarString {
public static void main(String[] args) {
System.out.print( "El " );
System.out.print( "Solsticio " );
System.out.print( "de " );
System.out.print( "invierno " );
System.out.print( "es " );
System.out.print( "en " );
System.out.print( "Diciembre en el Hemisferio Norte\n" );
} //fin de la clase main
} //fin de la clase MostrarString

PROGRAMA 52: ANALIZA EL PROGRAMA:---------------------------------------------------------------------------------------class PalabrasClave {


public static void main( String[ ] args ) {
String palabrasClave = "";
palabrasClave = palabrasClave + "videotutoriales ";
palabrasClave = palabrasClave + "flash " ;
palabrasClave = palabrasClave + "php ";
LIC.FLAVIO RAMOS ZETINA

Pgina 32

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


System. out.println( palabrasClave );
}
}
PROGRAMA 53: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------class PalabrasClave2 {
public static void main( String[ ] args ) {
String palabrasClave = "";
palabrasClave += "video tutoriales ";
palabrasClave += "flash " ;
palabrasClave += "php ";
System. out.println( palabrasClave );
}
}
PROGRAMA 54: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------class equals {
public static void main( String[] args ) {
String respuesta = "Amarillo";
String resultado = "Verde";
System.out.println( "Has respondido que el color es " + resultado + "?" );
System.out.println( "Respuesta:" + respuesta.equals( resultado ) );
} // fin del metodo main
} // fin de la clase equals

PROGRAMA 55: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------class length {


public static void main( String[] args ) {
LIC.FLAVIO RAMOS ZETINA

Pgina 33

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


String respuesta = "Amarillo";
String resultado = "Verde";
System.out.println( "Has respondido que el color es " + resultado + "?" );
System.out.println( "Respuesta:" + respuesta.equals( resultado ) );
int tam = respuesta.length();
System.out.println( tam );
} // fin del metodo main
} // fin de la clase length

PROGRAMA 56: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------class Elself{


public static void main(String args[]){
char grupo= 'A';
if( grupo =='A' ) {
System.out.println( "Formas parte del grupo A,enhorabuena!" );
}
else if( grupo == 'B' ) {
System.out.println( "Formas parte del grupo de los Aprovados!" );
}
else if( grupo == 'C' ) {
System.out.println( "Estas dentro del grupo de los suspensos!" );
}
else {
System.out.println( "Formas parte del Grupo D!" );
}
LIC.FLAVIO RAMOS ZETINA

Pgina 34

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


} // fin del metodo main
} // fin de la clase Elself

PROGRAMA 57: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------class If {


public static void main(String arg[]){
int puntuacion = 7;
if( puntuacion > 5){
System.out.println("En hora buena has, Aprovado");
}
} // fin del metodo main
} // fin de la clase if

PROGRAMA 58: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------class IfBloque {


public static void main(String arg[]){
int puntuacion = 9;
char grupo = 'C';

if( puntuacion >= 5 ){


System.out.println( "En hora buena has, Aprovado" );
System.out.println( "Tu nota final es: " + puntuacion );

grupo = 'A';

System.out.println( "Formas del Grupo: " + grupo );


LIC.FLAVIO RAMOS ZETINA

Pgina 35

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


}
} // fin del metodo main
} // fin de la clase IfBloque

PROGRAMA 59: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------class IfDos {


public static void main(String args[]){
int puntuacion = 9;
if( puntuacion == 7){
System.out.println( "Tienes un notable" );
}// fin de if

if( puntuacion == 3){


System.out.println("Tienes un insuficiente");
}// fin de if

System.out.println(" Nota final " + puntuacion);

} //fin de la clase main


} // fin de la clase IfDos

LIC.FLAVIO RAMOS ZETINA

Pgina 36

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


PROGRAMA 60: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------class IfElse {
public static void main(String arg[]){
int puntuacion = 5;
char grupo ;

if( puntuacion > 5 ) {


System.out.println( "En hora buena has, Aprovado" );
System.out.println( "Tu nota final es: " + puntuacion );
grupo = 'A';
}
else {
System.out.println( "Lo siento has suspendido!" );
System.out.println( "Tu nota final es: " + puntuacion );
grupo = 'B';

}
System.out.println( "Formas del Grupo: " + grupo );
} // fin del metodo main
} // fin de la clase IfElse
PROGRAMA 61: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------class IfString {
public static void main( String[ ] args ) {
String puntuacion = "nueve";
if ( puntuacion == "nueve" ) {
System. out. println( "Enhorabuena, sobre saliente!" ) ;
LIC.FLAVIO RAMOS ZETINA

Pgina 37

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


} // fin de la instruccion de seleccion simple ( if )
} // fin del metodo main
} // fin de la clase IfString
//Los Strings al ser objetos, no deben usarse con ellos los operadores == o !=
PROGRAMA 62: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------import java.util.*;
class Reloj {
public static void main( String[] arguments ) {
// obtener fecha y hora actual
Calendar ahora = Calendar.getInstance();
int hora = ahora.get( Calendar.HOUR_OF_DAY );
int minuto = ahora.get( Calendar.MINUTE );
int mes = ahora.get( Calendar.MONTH ) + 1;
int dia = ahora.get( Calendar.DAY_OF_MONTH );
int an = ahora.get( Calendar.YEAR );
// mostrar saludo
if ( hora < 12 ) {
System.out.println( "Buenos das.\n" );
} else if ( hora < 17 ) {
System.out.println( "Buenas tardes.\n" );
} else {
System.out.println( "Buenas noches.\n" );
}

// iniciar el mensaje horario mostrando las horas


System.out.print( "Son las" );
LIC.FLAVIO RAMOS ZETINA

Pgina 38

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


System.out.print( " " );
System.out.print( ( hora > 12) ? (hora - 12 ) : hora );
System.out.print( " horas " );

// mostrando los minutos


if ( minuto != 0 ) {
System.out.print( minuto + " " );
System.out.print( ( minuto != 1 ) ? "minutos " :
"minuto " );
}
// mostrar el da
System.out.println( "del da " + dia + " de ");

// mostrar el nombre del mes


switch ( mes ) {
case 1:
System.out.print( "Enero" );
break;
case 2:
System.out.print( "Febrero" );
break;
case 3:
System.out.print( "Marzo" );
break;
case 4:
System.out.print( "Abril" );
LIC.FLAVIO RAMOS ZETINA

Pgina 39

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


break;
case 5:
System.out.print( "Mayo" );
break;
case 6:
System.out.print( "Junio" );
break;
case 7:
System.out.print( "Julio" );
break;
case 8:
System.out.print( "Agosto" );
break;
case 9:
System.out.print( "Septiembre" );
break;
case 10:
System.out.print( "Octubre" );
break;
case 11:
System.out.print( "Noviembre" );
break;
case 12:
System.out.print( "Diciembre" );
}

LIC.FLAVIO RAMOS ZETINA

Pgina 40

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


// mostrar ao
System.out.println( " de " + an + "." );
}
}
PROGRAMA 63: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------class Switch{
public static void main(String args[]){
char grupo = 'B';

switch( grupo ){
case 'A':
System.out.println( "Tienes una A,Gran trabajo!" );
break;
case 'B':
System.out.println( "Tienes una B,Buen trabajo!" );
break;
case 'C':
System.out.println( "Tienes una C,Hay que trabajar mas!" );
break;
default:
System.out.println( "Tienes una D,Necesitas un gran cambio!" );
}
}
}

PROGRAMA 64: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------LIC.FLAVIO RAMOS ZETINA

Pgina 41

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


class Ternario {
public static void main(String args[]) {
int puntuacion = 10;

String mensaje;
mensaje = ( puntuacion>=5 ) ? "Enhora buena has Aprobado!" + "Tu nota final es"
+ puntuacion: "Lo siento has suspendido!" + "Tu nota final es " + puntuacion;

System.out.println( mensaje );
} // fin del metodo main
} // fin de la clase Ternario
PROGRAMA 65: ANALIZA ELPROGRAMA:------------------------------------------------------------------------------------------// Este programa genera
class AnidarLoops {
public static void main( String args[] ) {
int points = 0;
int target = 100;
// combinacion de while,for y if finalizando con break.
while ( target <= 100 ) // inicio de while
{
for ( int i = 0; i < target; i++ ) // inicio de for
{
if ( points > 50 ) // inicio de if
{
System.out.println ( "Saliendo del loop for" ); // indicador
break;
LIC.FLAVIO RAMOS ZETINA

Pgina 42

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


} // fin de if
points = points + i;
} // fin de for
} // fin de while
} // fin del metodo main
} // fin de class AnidarLoops
PROGRAMA 66: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------class ComplejidadLoops {
// El metodo main empieza la ejecucion en java.
public static void main( String args[] ) {
int i, j;
for ( i = 0, j = 0; i * j < 1000; i++, j += 2) // inicializa for
{
System. out. println( i + " * " + j + " = " + ( i * j ) );
} // fin for
} // fin del metodo main
} // fin de class ComplejidadLoops
PROGRAMA 67: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------import static java. lang. System. out;
class Contador {
public static void main( String args[ ] )
{
for ( int contador = 1; contador <= 10; contador++) // inicializa for
{
out. print( "El valor del contador es: " ) ;
out. print( contador );
LIC.FLAVIO RAMOS ZETINA

Pgina 43

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


out. println( " . " );
} // fin de for
out. println( " Hecho! " );
} // fin del metodo main
} // fin de class Contador
PROGRAMA 68: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------class ContinueLoop {
public static void main(String args[] ) {
int index = 0;
while ( index <= 1000 ) // inicializa while
{
index = index + 5;
if ( index == 400 )
continue;
System. out. println( " El index es " + index );
} // fin de while
} // fin del metodo main
} // fin de class ContinueLoop

PROGRAMA 69: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------import static java. lang. System. out;


import java. util. Scanner;
LIC.FLAVIO RAMOS ZETINA

Pgina 44

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


import java. util. Random;
class Juego {
public static void main( String args[ ] ) {
Scanner miScanner = new Scanner( System. in );
int numIntentos = 0;
int numAleatorio = new Random() . nextInt( 10) + 1;

out. println("

******* *****

" );

out. println(" Bienvenido al juego \"Acierta el Nmero!!\"" );


out. println("

******* *****

" );

out. println() ;
out. print( "Escribe un nmero del 1 al 10: " );
// empieza int con un contador
int numeroEscrito = miScanner. nextInt();
numIntentos++;
// Comienza la programacion con while
while (numeroEscrito != numAleatorio) // inicializa while
{
out. println( ) ;
out. println( " Intntalo de nuevo. . . ");
out. print(" Escribe un nmero del 1 al 10: " );
numeroEscrito = miScanner. nextInt();
numIntentos++;
} // fin de while
out. print( "Has Ganado despus de " );
out. println(numIntentos + " intentos. " );
LIC.FLAVIO RAMOS ZETINA

Pgina 45

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


} // fin del metodo main
} // fin de class Juego
PROGRAMA 70: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------import java.io.File;
import static java.lang.System.out;
import java. util. Scanner;
class LoopDo {
public static void main( String args[] ) {
File archivo = new File( "c:\\miArchivo.txt" );

Scanner miScanner = new Scanner ( System.in );


char replica;
// empieza la conbinacion a ejecutar
do
{ // inicializa do
out. print("Borrar archivo? (s/ n) " ) ;
replica = miScanner. findWithinHorizon( "." , 0) . charAt( 0) ;
} // fin de do
while (replica != 's' && replica != 'n' ) ;
if ( replica == 's' )
{ // inicializa if
out. println( "De acuerdo, borrando archivo. . . ") ;
archivo. delete() ;
} // fin de if
else
{ // inicializa else
LIC.FLAVIO RAMOS ZETINA

Pgina 46

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


out. println( "De acuerdo, confirmado no borrar. ") ;
} // fin else
} // fin del metodo main
} // fin de class LoopDo
PROGRAMA 71: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------import java.io.File;
import static java.lang.System.out;
import java. util. Scanner;
class LoopDo2 {
public static void main( String args[] ) {
File archivo = new File( "c:\\miArchivo.txt" );
Scanner miScanner = new Scanner (System.in);
char replica;
do
{ // inicializa do
out. print("Borrar archivo? (s/ n) " );
replica = miScanner. findWithinHorizon( "." , 0) . charAt( 0);
} // fin de do
while ( replica != 's' && replica != 'n' && replica != 'S' && replica != 'N' );
if ( replica == 's' || replica == 'S' )
{ // inicializa if
out. println( "De acuerdo, borrando archivo. . . ") ;
archivo. delete() ;
} // fin de if
else
{ // inicializa else
LIC.FLAVIO RAMOS ZETINA

Pgina 47

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


out. println( "De acuerdo, confirmado no borrar. ") ;
} // fin de else
} // fin del metodo main
} // fin de class LoopDo2
PROGRAMA 72: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------import java.util.*;
class MedidorVelocidad {
public static void main( String[ ] args ) {
Calendar start = Calendar. getInstance();
int startMinute = start.get(Calendar. MINUTE);
int startSecond = start.get(Calendar. SECOND);
start.roll(Calendar.MINUTE, true);
int nextMinute = start. get(Calendar. MINUTE);
int nextSecond = start. get(Calendar. SECOND);
int index = 0;

while ( true )
{ // inicializa while Y dentro se encuentra if dentro de otro if
double x = Math.sqrt(index) ;
GregorianCalendar now = new GregorianCalendar() ;

if (now. get(Calendar.MINUTE) >= nextMinute)


{ // inicializa if dentro de while
if ( now.get(Calendar.SECOND) >= nextSecond)
{ // inicializa if dentro de if dentro de otro if y dentro de while
break; // detenlo en su momento
LIC.FLAVIO RAMOS ZETINA

Pgina 48

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


} // finaliza if dentro de if y dentro de while
} // finilisa if dentro while
index++; // contador
} // fin de while
System. out.println(index + " loops en un minuto." ); // indicador
} // fin del metodo main
} // fin de class MedidorVelocidad
PROGRAMA 73: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------import static java. lang. System. out;
class Multiplo {
public static void main(String[ ] arguments) {
for (int x = 1; x <= 200; x++) {
int multiplo = 7 * x;
out. print(multiplo + " ");
}
}

PROGRAMA 74: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------class NombrarLoops {


public static void main(String args[] ) {
int points = 0;
int target = 100;
targetLoop:
while (target <= 100) {
for (int i = 0; i < target; i++) {
if (points > 50) {
LIC.FLAVIO RAMOS ZETINA

Pgina 49

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


System.out.println("points = "+ points);
System.out.println("Saliendo de los dos loops");
break targetLoop;}
points = points + i;
}
}
}
}
PROGRAMA 75: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------class SalirLoop {
public static void main(String args[] ) {
int index = 0;
while (index <= 1000) {
index = index + 5;
System.out. println( index) ;
if (index == 400) {
System.out. println( "index = 400. Saliendo.... ") ;
break;
}
}
}
}
PROGRAMA 75: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------VIDEO 9
class EliminarEspacio {
public static void main(String[ ] args) {
LIC.FLAVIO RAMOS ZETINA

Pgina 50

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


String citaDiaria = "La educacin consiste en ensear a los hombres no lo que deben pensar sino a
pensar.";
char[] convertir = citaDiaria.toCharArray() ;
for (int dex = 0; dex < convertir. length; dex++) {
char current = convertir[dex] ;
if (current != ' ' ) {
System.out. print(current);
}
else {
System.out. print('.' );
}
}
}
}
PROGRAMA 76: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------class Length {
public static void main(String[]args) {
String [ ] marcasImpresoras = { "Brother", " Canon", " Dell", "Epson", "HP" , "Lexmark" , "Olivetti", "
Samsung"};
System.out.println ("Hay " +marcasImpresoras.length + " marcas de impresoras.");
}
}

PROGRAMA 77: ANALIZA EL PROGRAMA:-----------------------------------------------------------------------------------------import java.util.*;


class Nombre {
public static void main(String[ ] args) {
LIC.FLAVIO RAMOS ZETINA

Pgina 51

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


String nombres[ ] = { "Miguel" , "Mara", "Alberto", "Fernando",
"Alejandro", "Rosa" , "Evaristo", "Bernardo", "Francisco" ,
"Homero", "Cristina" , "Carla", "Csar" };
System. out.println("El orden original:" ) ;
for (int i = 0; i < nombres. length; i++) {
System.out.print( i + " : " + nombres[i] + " " );
}
Arrays.sort(nombres) ;
System. out.println("\nEl nuevo orden: ");
for (int i = 0; i < nombres. length; i++) {
System.out.print( i + " : " + nombres[i] + " " );
}
System. out.println();
}
}

PROGRAMA 78: ANALIZA EL PROGRAMA:


class Rueda {
public static void main(String[ ] args) {
String frase[] = {
"TODA CUESTION TIENE DOS PUNTOS DE VISTA",
"EL EQUIVOCADO Y EL NUESTRO" ,
"TODAS LAS MUJERES TIENEN ALGO HERMOSO",
"AUNQUE SEA UNA PRIMA LEJANA",
"SE ESTA MURIENDO GENTE QUE ANTES NO SE MORIA",
LIC.FLAVIO RAMOS ZETINA

Pgina 52

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


"HE OIDO HABLAR TAN BIEN DE TI",
"QUE CREIA QUE ESTABAS MUERTO",
"RECUERDA SIEMPRE QUE ERES UNICO",
"EXACTAMENTE IGUAL QUE TODOS LOS DEMAS" ,
"TODO TIEMPO PASADO FUE ANTERIOR." ,
"LOS HONESTOS SON INADAPTADOS SOCIALES",
"LA VERDAD ABSOLUTA NO EXISTE" ,
"Y ESTO ES ABSOLUTAMENTE CIERTO",
"LO TRISTE NO ES IR AL CEMENTERIO, SINO QUEDARSE",
"EL AMOR ETERNO DURA APROXIMADAMENTE TRES MESES"
};
int[ ] contadorLetras = new int[26] ;
for (int contador = 0; contador< frase.length; contador++) {
String actual = frase[contador];
char[] letras = actual.toCharArray();
for (int contador2 = 0; contador2 < letras.length; contador2++) {
char let = letras[contador2];
if ( (let >= 'A' ) & (let <= 'Z' ) ) {
contadorLetras[let - 'A' ]++;
}
}
}
for (char contador = 'A' ; contador <='Z'; contador++) {
System.out.print( contador + ":" +
contadorLetras[contador - 'A' ] +
" ") ;
LIC.FLAVIO RAMOS ZETINA

Pgina 53

PROGRAMACION JAVA PRIMER SEMESTRE 03/02/2013


}
System. out.println();
}
}

LIC.FLAVIO RAMOS ZETINA

Pgina 54

Vous aimerez peut-être aussi