viernes, 21 de octubre de 2011

Sinónimos y antónimos - Java

 1 package sinonimosantonimos;
 2 
 3 import java.io.BufferedReader;
 4 import java.io.IOException;
 5 import java.io.InputStreamReader;
 6 
 7 
 8 public class SinonimosAntonimos 
 9 {
10     public static classDiccionario DicCompleto[] = new classDiccionario[20];
11     
12     public static void main(String[] args) throws IOException 
13     {
14 
15         int i = 0;
16         int cont=-1;
17         int opcion=99;
18         
19         //classDiccionario DicCompleto[] = new classDiccionario[2];
20         
21         InputStreamReader ISR = new InputStreamReader(System.in);
22         BufferedReader bftexto = new BufferedReader(ISR);  
23         
24         do 
25         {
26             System.out.println("Ingrese opcion");
27             System.out.println("--------------");
28             System.out.println("1.- Ingresar palabras");
29             System.out.println("2.- Desplegar palabras");
30             System.out.println("3.- Buscar palabra");
31             System.out.println("0.- Salir");
32             opcion = Integer.parseInt(bftexto.readLine());
33             if (opcion!=0)
34             {
35                 switch (opcion)
36                 {
37                     case 1:cont=fnIngresaPalabras(cont+1);
38                            break;
39                     case 2:prDespliegaPalabras(cont);
40                            break;
41                 }
42             }
43         }
44         while (opcion!=0);
45             
46     }
47     
48     public static int fnIngresaPalabras(int i) throws IOException
49     {
50         String palabra;
51         String sinonimo;
52         String antonimo;
53                 
54         InputStreamReader ISR = new InputStreamReader(System.in);
55         BufferedReader bftexto = new BufferedReader(ISR);      
56         
57         do
58         {
59             System.out.print("Ingrese palabra : ");
60             palabra = bftexto.readLine();
61             if (!palabra.equals("XXX"))
62             {
63                 System.out.print("Ingrese Sinonimo : ");
64                 sinonimo = bftexto.readLine();
65                 System.out.print("Ingrese antonimo : ");
66                 antonimo = bftexto.readLine();
67                 DicCompleto[i] = new classDiccionario(palabra,sinonimo,antonimo);
68                 i++;
69                 if (i>DicCompleto.length-1)
70                 {
71                     System.out.println("No es posible agregar elementos");
72                     palabra = "XXX";
73                 }
74             }
75         }
76         while (!palabra.equals("XXX"));
77         return(i-1);
78     }
79     
80     public static void prDespliegaPalabras(int cont)
81     {
82         int i;
83         for (i=0;i<=cont;i++)
84             System.out.println(DicCompleto[i].getPalabra()+" "+
85                                DicCompleto[i].getSinonimo()+" "+
86                                DicCompleto[i].getAntonimo());
87     }
88 }



Vehículo llamando a clases - Java

 1 
 2 package clasevehiculos;
 3 
 4 
 5 public class ClaseVehiculos 
 6 {
 7 
 8     public static void main(String[] args) 
 9     {
10       Vehiculos auto = new Vehiculos(4, 4, 6); 
11 
12       if (auto.isEncendido())
13           System.out.println("Auto Encendido");
14       else
15           System.out.println("Auto Apagado");
16       
17       auto.darContacto();
18       
19       if (auto.isEncendido())
20           System.out.println("Auto Encendido");
21       else
22           System.out.println("Auto Apagado");
23       
24       auto.ponerEnMarcha();
25       
26       if (auto.isEnMarcha())
27           System.out.println("Auto en marcha");
28       else
29           System.out.println("Auto detenido");
30       
31       auto.quitarContacto();
32       
33       if (auto.isEncendido())
34           System.out.println("Auto Encendido");
35       else
36           System.out.println("Auto Apagado");
37       
38       auto.detenerMarcha();
39       
40       if (auto.isEnMarcha())
41           System.out.println("Auto en marcha");
42       else
43           System.out.println("Auto detenido");
44       
45       auto.quitarContacto();
46       
47       if (auto.isEncendido())
48           System.out.println("Auto Encendido");
49       else
50           System.out.println("Auto Apagado");
51           
52     }
53 }

Palíndromas - Java

 1 
 2 package palindromas;
 3 
 4 import java.io.BufferedReader;
 5 import java.io.IOException;
 6 import java.io.InputStreamReader;
 7 
 8 
 9 public class Palindromas 
10 {
11 
12 
13     public static void main(String[] args) throws IOException 
14     {
15         String texto;
16         int i;
17         int j;
18         boolean esPalindroma = true;
19                 
20         InputStreamReader ISR = new InputStreamReader(System.in);
21         BufferedReader bftexto = new BufferedReader(ISR);
22         
23         texto = bftexto.readLine();
24         
25         j=texto.length()-1;
26         for (i=0;i<texto.length() && j>=i;i++)
27             if (!texto.substring(i,i+1).equals(texto.substring(j,j+1)))
28                 esPalindroma = false;
29             else
30                 j = j - 1;
31         
32         if (esPalindroma)
33             System.out.println("La palabra "+texto+" es palindroma");
34         else
35             System.out.println("La palabra "+texto+" no es palindroma");
36         
37         
38         
39     }
40 }

Leer datos - Java

 1 
 2 package leerdatos;
 3 
 4 import java.io.*;
 5 
 6 public class LeerDatos 
 7 {
 8 
 9     public static void main(String[] args) throws IOException 
10     {
11         String nombres;
12         String apellidos;
13         String Num1;
14         String Num2;
15         int N1;
16         int N2;
17         int N3;
18       
19         InputStreamReader ISR = new InputStreamReader(System.in);
20         BufferedReader texto = new BufferedReader(ISR) ;
21         
22         /*System.out.print("Ingrese nombres ... ");
23         nombres = texto.readLine();
24         System.out.print("Ingrese apellidos ... ");
25         apellidos = texto.readLine();
26         System.out.println(nombres);
27         System.out.println(apellidos); */
28         
29         /*System.out.print("Ingrese primer numero ");
30         Num1 = texto.readLine();
31         System.out.print("Ingrese segundo numero ");
32         Num2 = texto.readLine();*/
33         
34         System.out.print("Ingrese primer numero ");
35         N1 = Integer.parseInt(texto.readLine());
36         System.out.print("Ingrese segundo numero ");
37         N2 = Integer.parseInt(texto.readLine());
38         
39         N3 = N1 + N2;
40         
41         System.out.println("La suma es "+N3);
42         
43         
44       }
45 }

Hola Mundo "Java"

 1 
 2 package holamundo;
 3 
 4 import java.util.*;
 5 
 6 public class HolaMundo {
 7     
 8     
 9     public static void main(String[] args) {
10             System.out.print("Hola mundo ");
17         
18     }
19 }

Arreglos - llenar automáticamente

 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 
 4 int main(){
 5      printf("\n\n");
 6   printf("            -* PROGRAMA DE ARREGLOS *-\n");
 7      printf("              --------------------\n\n\n\n");
 8 int cantidad; 
 9 int cantidadF;
10 int cont=0;
11 printf("Ingrese la cantidad de numeros del arreglo: ");
12 scanf("%d",&cantidad);
13 printf("\n");
14 //el arreglo es del indice de cantidad
15 int arreglo1[cantidad];
16 for(int i=0;i<=cantidad;i++){
17 arreglo1[i]=i;
18 printf("%i",arreglo1[i]);
19 
20 } 
21 printf("\n\n");
22 //En el caso de una matriz (prueba con 3x3) 
23 printf("Ingrese la cantidad de filas del arreglo: "); 
24 scanf("%d",&cantidadF); 
25 printf("Ingrese la cantidad de columnas del arreglo: "); 
26 scanf("%d",&cantidad);
27 printf("\n");
28 //menos uno porque me contará el cero
29 int arreglo2[cantidadF-1][cantidad-1]; 
30 for(int i=0;i<=cantidadF-1;i++){
31 for(int b=0;b<=cantidad-1;b++){
32   cont++;
33 arreglo2[i][b]=cont;
34 printf("%i  ",arreglo2[i][b]);
35 }
36 printf("\n");
37 }
38 printf("\n\n");
39 
40 system("PAUSE");
41 }

Hola Mundo !

   Bueno este blog está dedicado solo a publicar códigos fuentes de diferentes lenguajes de programación, cosa que cuando haga alguno lo publique y tenga algún recuerdo de él.

y para empezar mi primer código en C.


 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 
 4 int main(){
 5 
 6     printf("hola mundo !\n\n\n\n");
 7     
 8     system("PAUSE");
 9     return 0;
10 }
 

Solo se puede compilar en un sistema de consola windows ms-dos.