Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package generateclado;
  7.  
  8. /**
  9. *
  10. * @author DAM 1
  11. */
  12. public class GeneraTeclado {
  13.  
  14. /**
  15. * @param args the command line arguments
  16. */
  17. public static void main(String[] args) {
  18. Teclado t=new Teclado();
  19. //System.out.println("hey");
  20. t.introduceInt2(10,1);
  21. t.introduceINT();
  22. t.introduceString();
  23. t.introduceChar();
  24. }
  25.  
  26. }
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37. /*
  38. * To change this license header, choose License Headers in Project Properties.
  39. * To change this template file, choose Tools | Templates
  40. * and open the template in the editor.
  41. */
  42. package generateclado;
  43.  
  44. import java.util.Scanner;
  45.  
  46. /**
  47. *
  48. * @author DAM 1
  49. */
  50. public class Teclado {
  51.  
  52. public Teclado() {
  53. }
  54.  
  55. public int introduceINT() {
  56. System.out.println("Introudce un numero");
  57. int num = 0;
  58. Scanner sc = new Scanner(System.in);
  59. try{
  60. num = sc.nextInt();
  61. }catch(Exception ay){
  62. System.out.println("Has introducido mal los datos, el error ha sido: "+ay);
  63. }
  64. return num;
  65. }
  66.  
  67. public int introduceInt2(int max, int min) {
  68. boolean repetir = false;
  69. int num = 0;
  70. do {
  71. try {
  72. Scanner sc = new Scanner(System.in);
  73. System.out.println("Introduce numero");
  74. num = sc.nextInt();
  75. if (max > num && min < num) {
  76. //System.out.println("hhhheeeeeee3eeeoooo");
  77. //repetir=true;
  78. break;
  79. }
  80. } catch (Exception heeey) {
  81. System.out.println("Has introducido mal los datos, el error ha sido: " + heeey);
  82. }
  83. } while (true);
  84. return num ;
  85. }
  86.  
  87. public String introduceString(){
  88. System.out.println("Introduce tu palabra");
  89. String pal="";
  90. Scanner sc = new Scanner(System.in);
  91. pal=sc.nextLine();
  92. return pal;
  93. }
  94.  
  95. public char introduceChar(){
  96.  
  97. String letras="";
  98. char l;
  99. Scanner sc = new Scanner(System.in);
  100. while(true){
  101. System.out.println("Introduce tu letra");
  102. letras=sc.nextLine();
  103. if(letras.length()==1){
  104. break;
  105. }else{
  106. System.out.println("Has introducido mas de un caracter");
  107. }
  108. }
  109. l=letras.charAt(0);
  110. return l;
  111. }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement