Skip to content

Instantly share code, notes, and snippets.

@DiegoTc
Created November 8, 2017 19:54
Show Gist options
  • Save DiegoTc/b8e928a23d68389030f8f16bbb748ac2 to your computer and use it in GitHub Desktop.
Save DiegoTc/b8e928a23d68389030f8f16bbb748ac2 to your computer and use it in GitHub Desktop.
Respuestas de los ejercicios de los examenes
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package examenI;
import java.util.Scanner;
/**
*
* @author dturcios
*/
public class Ejercicio2 {
public static void main(String[] args) {
Scanner leer = new Scanner(System.in);
System.out.print("Ingrese un numero: ");
int num1 = leer.nextInt();
System.out.print("Ingrese otro numero: ");
int num2 = leer.nextInt();
System.out.println("La respuesta es: "+ num1+ num2);
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package examenI;
import java.util.Scanner;
/**
*
* @author dturcios
*/
public class Ejercicio3 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int opcion =0;
String oneword = "";
String copyword;
do{
System.out.println("Palindromo");
System.out.println("1) Es palindromo?");
System.out.println("2) Salir");
opcion = sc.nextInt();
switch(opcion){
case 1:
System.out.println("Palindromo");
System.out.println("Ingrese la palabra para saber si palindromo: ");
oneword = sc.next();
System.out.println("Usando arrays");
char []onewordArray = oneword.toCharArray();
for(int i=0;i<(onewordArray.length-1)/2;i++){
char temp = onewordArray[i];
onewordArray[i] = onewordArray[onewordArray.length-1];
onewordArray[onewordArray.length-1] = temp;
}
copyword = new String(onewordArray);
if(oneword.equals(copyword)){
System.out.println("La palabra "+ oneword + " si es palindromo");
}
else{
System.out.println("La palabra "+ oneword + " No es palindromo");
}
System.out.println("Usando el string");
String secondword="";
for(int i=oneword.length()-1; i>=0 ;i--){
secondword = secondword + oneword.charAt(i);
}
if(secondword.equals(oneword)){
System.out.println("La palabra "+ oneword + " si es palindromo");
}
else{
System.out.println("La palabra "+ oneword + " No es palindromo");
}
}
}while(opcion!=2);
}
}
package examenI;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author dturcios
*/
public class Ejercicio4 {
public static void main(String[] args) {
for(int i=5;i>0;i--){
for(int j=0;j<i;j++){
System.out.print("*");
}
System.out.println();
}
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package examenI;
import java.util.Scanner;
/**
*
* @author dturcios
*/
public class Ejercicio5 {
public static void main(String[] args) {
Scanner leer = new Scanner(System.in);
int opcion =0;
do{
System.out.println("Menu");
System.out.println("1) Tirar dado");
System.out.println("2) Salir");
System.out.print("Ingrese opcion: ");
opcion = leer.nextInt();
switch(opcion){
case 1:
System.out.println("Se va a lanzar el dado:");
System.out.println("El numero que se lanzo fue: "+ (1+(int)(Math.random()*(6-1)+1)));
System.out.println("El numero que se lanzo fue: "+ ((int)(Math.random()*6)));
break;
case 2:
break;
default:
System.out.println("Ingrese una opcion valida");
}
}while (opcion!=2);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment