Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Helper {
- public static int valEnteroPositivo(Scanner sc, String message) {
- int num;
- String reply;
- while(true) {
- try {
- do {
- System.out.println(message);
- reply=sc.nextLine();
- num=Integer.parseInt(reply);
- if(num>0) {
- return num;
- }else {
- System.out.println("Error el numero entero debe ser positivo...");
- }
- }while(num<0);
- break;
- }
- catch (Exception e) {
- System.out.println("Error debe ingresar un numero entero....");
- }
- }
- return num;
- }
- public static char Caracterval(Scanner sc,String message) {
- char character;
- while (true) {
- try {
- System.out.print(message);
- character = sc.nextLine().charAt(0);
- break;
- }
- catch (Exception StringIndexOutOfBoundsException) {
- System.out.println("S\n ERROR de ingreso ");
- }
- }
- return character;
- }
- public static char Validacionrst(Scanner sc, String message) {
- char rta;
- do {
- rta=Caracterval(sc,message);
- if ( rta!='s' & rta!='S' & rta!='N' & rta!='n' ) {
- System.out.println("Error !! Ingrese S o N"); }
- } while ( rta!='s' & rta!='S' & rta!='N' & rta!='n' );
- return rta ;
- }
- public static int valEntero(Scanner entrada, String message) {
- int num;
- String reply;
- while(true) {
- try {
- System.out.println(message);
- reply=entrada.nextLine();
- num=Integer.parseInt(reply);
- break;
- }
- catch (Exception e) {
- System.out.println("Error....");
- }
- }
- return num;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment