Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * 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 generateclado;
- /**
- *
- * @author DAM 1
- */
- public class GeneraTeclado {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- Teclado t=new Teclado();
- //System.out.println("hey");
- t.introduceInt2(10,1);
- t.introduceINT();
- t.introduceString();
- t.introduceChar();
- }
- }
- /*
- * 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 generateclado;
- import java.util.Scanner;
- /**
- *
- * @author DAM 1
- */
- public class Teclado {
- public Teclado() {
- }
- public int introduceINT() {
- System.out.println("Introudce un numero");
- int num = 0;
- Scanner sc = new Scanner(System.in);
- try{
- num = sc.nextInt();
- }catch(Exception ay){
- System.out.println("Has introducido mal los datos, el error ha sido: "+ay);
- }
- return num;
- }
- public int introduceInt2(int max, int min) {
- boolean repetir = false;
- int num = 0;
- do {
- try {
- Scanner sc = new Scanner(System.in);
- System.out.println("Introduce numero");
- num = sc.nextInt();
- if (max > num && min < num) {
- //System.out.println("hhhheeeeeee3eeeoooo");
- //repetir=true;
- break;
- }
- } catch (Exception heeey) {
- System.out.println("Has introducido mal los datos, el error ha sido: " + heeey);
- }
- } while (true);
- return num ;
- }
- public String introduceString(){
- System.out.println("Introduce tu palabra");
- String pal="";
- Scanner sc = new Scanner(System.in);
- pal=sc.nextLine();
- return pal;
- }
- public char introduceChar(){
- String letras="";
- char l;
- Scanner sc = new Scanner(System.in);
- while(true){
- System.out.println("Introduce tu letra");
- letras=sc.nextLine();
- if(letras.length()==1){
- break;
- }else{
- System.out.println("Has introducido mas de un caracter");
- }
- }
- l=letras.charAt(0);
- return l;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement