INDICE | ANTERIOR | SIGUIENTE | PÁGINA PERSONAL |
import java.io.*; public class Problema1 { public static void main( String[] args ) throws Exception { BufferedReader teclado; long pesetas; double euros; String linea; teclado = new BufferedReader( new InputStreamReader(System.in) ); System.out.print("Cantidad (pts): "); linea = teclado.readLine(); pesetas = Integer.parseInt(linea); euros = pesetas/166.387; System.out.println(pesetas+" pts. corresponden a "+euros+" euros."); } }
import java.io.*; public class Problema2 { public static void main( String[] args ) throws Exception { BufferedReader teclado; long pesetas; double euros; String linea; teclado = new BufferedReader( new InputStreamReader(System.in) ); System.out.print("Cantidad (pts): "); linea = teclado.readLine(); try { pesetas = Integer.parseInt(linea); euros = pesetas/166.387; System.out.println(pesetas+" pts. corresponden a "+euros+" euros."); } catch( Exception e ) { System.out.println("No ha introducido un valor correcto."); } } }
import java.io.*; public class Problema3 { public static void main( String[] args ) throws Exception { BufferedReader teclado; long pesetas; double euros; String linea; int n; teclado = new BufferedReader( new InputStreamReader(System.in) ); System.out.print("Cantidad: "); linea = teclado.readLine().toUpperCase(); if( linea.endsWith(" PTS") ) { n = linea.indexOf(" PTS"); linea = linea.substring(0,n); try { pesetas = Integer.parseInt(linea); euros = pesetas/166.387; System.out.println(euros+" euros"); } catch( Exception e ) { System.out.println("'"+linea+"' no es un numero entero valido."); } } else if( linea.endsWith(" EUROS") ) { n = linea.indexOf(" EUROS"); linea = linea.substring(0,n); try { euros = Double.valueOf(linea).doubleValue(); pesetas = Math.round(euros*166.387); System.out.println(pesetas+" pts"); } catch( Exception e ) { System.out.println("'"+linea+"' no es un numero real valido."); } } else { System.out.println("La linea debe terminar con 'pts' o 'euros'"); } } }
import java.io.*; public class Problema4 { public static void main( String[] args ) throws Exception { BufferedReader teclado; int min = 0; int max = 1000; int med; char resp; String linea; teclado = new BufferedReader( new InputStreamReader(System.in) ); System.out.println("*** ADIVINA UN NUMERO ***"); System.out.println(""); System.out.println("Piense un numero de 1 a 1000"); do { med = (min+max)/2; System.out.print("Es menor de "+med+"? [S/N] "); linea = teclado.readLine().toUpperCase(); resp = linea.charAt(0); if( resp == 'S' ) max = med-1; else min = med; } while( max>min ); System.out.println("LO TENGO! La respuesta es "+max+"."); } }
import java.io.*; public class Problema5 { public static void main( String[] args ) { new Problema5(); } public Problema5( ) { BufferedReader teclado; String linea; int a,b,x; teclado = new BufferedReader( new InputStreamReader(System.in) ); System.out.print("Escriba el primer valor: "); linea = teclado.readLine(); try { a = Integer.parseInt(linea); System.out.print("Escriba el segundo valor: "); linea = teclado.readLine(); b = Integer.parseInt(linea); x = mcd(a,b); System.out.println("El m.c.d. es "+x); } catch( Exception e ) { System.out.println("El valor introducido es erroneo."); } } // Algoritmo de Euclides public int mcd( int x, int y ) { int a,b; a = x; b = y; while( a != b ) { if( a < b ) { b = b - a; } else { a = a - b; } } return(a); } }
INDICE | ANTERIOR | SIGUIENTE |