Advertisement
gabuwu

TP04-EJ4-G3.3-HELPER

Oct 27th, 2021
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. package TP4;
  2.  
  3. import java.util.Random;
  4. import java.util.Scanner;
  5.  
  6. public class Helper {
  7.  
  8. Random random = new Random();
  9. Scanner scanner = new Scanner(System.in);
  10.  
  11. public int leerNum (){
  12. int num = 0 ;
  13. boolean band = true;
  14.  
  15. while (band) {
  16. print("Ingrese un numero entero positivo");
  17.  
  18. try{
  19.  
  20. int aux =scanner.nextInt();
  21. if (aux>0) {
  22. band=false;
  23.  
  24. num=aux;
  25. } else {
  26. print("El numero ingresado no cumple la condicion... Ingrese nuevamente\n");
  27. }
  28.  
  29. }catch(Exception e) {
  30. print("Valor incorrecto... Ingrese nuevamente\n");
  31. }
  32. }
  33.  
  34. return num;
  35.  
  36. }
  37. public boolean continuar() {
  38. boolean seguir = true;
  39.  
  40. int opc = scanner.nextInt();
  41. if (opc == 1) {
  42. seguir= true;
  43. }else {
  44. seguir=false;
  45. print("\n--------------\nFin del programa...\n----------------");
  46. }
  47.  
  48. return seguir;
  49.  
  50. }
  51.  
  52.  
  53. public int generarRand () {
  54.  
  55. int numRand =(int) (Math.random()*200+1);
  56. System.out.println("El numero aleatorio genrado es: "+numRand);
  57. return numRand;
  58.  
  59. }
  60. public void print(String texto) {
  61. System.out.println(texto);
  62. }
  63.  
  64. public String toString(int num) {
  65. return Integer.toString(num);
  66.  
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement