Hola gente:
 
Tengo un proyecto por consola al cual se debe ingresar el nombre, apellido y rut.
 
Necesito poder validar el rut, el cual debe tener 11 caracteres máximo.
 
Me explico:
 
Se debe ingresar el rut sin puntos, sin guión y sin el dígito verificador.
 
Al poner un rut como 6985222, me tire un cero a la izquierda y el guión con el dígito verificador a la derecha.
 
6985222 ------------> 06985222-7,  por ejemplo.
 
No he encontrado información de cómo hacer esto.
 
 
Esta es mi clase por consola:
 
 
import java.sql.*;
import java.util.*;
import java.io.*;
 
public class ProcedimientoAgregar {
 
	private Connection Conexion;
	private CallableStatement cstmt = null ;
 
 
	public ProcedimientoAgregar(Connection Con) {
 
		Conexion = Con;
	}
 
	public static void Agregar() throws Exception
	{
	Class.forName("com.microsoft.sqlserver.jdbc.SQLSer  verDriver");
	Connection con=DriverManager.getConnection("jdbc:sqlserver://MARTE:1433;DatabaseName=Prueba", "sa", "gsiinformatica");
	//Step-1
 
	CallableStatement cstmt = con.prepareCall("{call ProcedAlmac_IngresarPersona(?,?,?)}");
	Scanner sc=new Scanner(System.in);
 
	Scanner consola = new Scanner(System.in);
	BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
	int opcion = 0;
	String seleccion = "";
 
 
	// Si fuese integer System.out.print("Ingrese el numero tanto: ");
	//int x=sc.nextInt();
 
	System.out.println ("************************************");
	System.out.println ("************************************");
	System.out.println ("**                                **");
	System.out.println ("**         MODULO DE CARGAS       **");
	System.out.println ("**                                **");
	System.out.println ("** 1 - Ingreso de datos           **");
	System.out.println ("**                                **");
	System.out.println ("************************************");
	System.out.println ("************************************");
 
	System.out.println ("");
 
	System.out.print("Ingrese el nombre: ");
	String nombre = sc.next().toUpperCase();
 
	System.out.print("Ingrese el apellido: ");
	String apellido = sc.next().toUpperCase();
 
	System.out.println("Ingrese el RUT sin puntos ni guion y sin digito verificador. Ej: 12114175 ");
	String rut = sc.next().toUpperCase();
	//Step-2
	cstmt.setString(1,nombre);
	cstmt.setString(2,apellido);
	cstmt.setString(3,rut);
	//Step -3
	cstmt.execute();
	System.out.println("***Llamada a Procedimiento Almacenado****");
	System.out.println("Registro Agregado con Exito!!!!!!");
	con.close();
 
try{
 
do{	
	System.out.println("");
	System.out.println("Desea seguir ingresando personas?");
 
	System.out.println("");
	System.out.println(" Opcion 1: Seguir - Opcion 2: Salir");
	opcion = consola.nextInt();
 
	switch (opcion) {
	    case 1:
	    System.out.println("Opcion 1: Seguir");
	    System.out.println("");
	    ProcedimientoAgregar.Agregar();
	     break;
	   case 2:
	      System.out.println("Opcion 2: Salir");
	      System.out.println("");
	      System.out.println("\nHasta Pronto!!!");
		  System.exit(2);
	      break;
	   default:
	     System.out.println("Seleccion no valida");
	     System.out.print("Pulse S si desea continuar o cualquier tecla y luego ENTER para salir: ");
	     seleccion = stdin.readLine();
	   }
	} while (seleccion.equals("s"));
	System.out.println("\nHasta Pronto!!!");
	System.exit(4);
 
}catch(java.util.InputMismatchException ex){
	System.out.println ("LA ENTRADA DEBE SER NUMERICA SOLAMENTE.");
	System.exit(4);
}
 
}
 
} 
  
 

