Foros del Web » Programación para mayores de 30 ;) » Java »

error? ayuda :/

Estas en el tema de error? ayuda :/ en el foro de Java en Foros del Web. Código: try{ int proximo = scanner.nextInt(); if(proximo>=100 || proximo==0){ throw new Exception(); } }catch(Exception e){ System.out.println("Debes ingresar un valor del tipo int (del 1 al ...
  #1 (permalink)  
Antiguo 20/03/2009, 11:24
 
Fecha de Ingreso: diciembre-2006
Mensajes: 60
Antigüedad: 17 años, 4 meses
Puntos: 0
error? ayuda :/

Código:
        try{
            int proximo = scanner.nextInt();
            if(proximo>=100 || proximo==0){
                throw new Exception();
            }
        }catch(Exception e){
            System.out.println("Debes ingresar un valor del tipo int (del 1 al 100)");
            System.exit(0);
        }
        for(int i=0;i>=proximo;int++;){

        }
        html.close();
hola, tengo un problema en el código anterior :/
pasa que la variable proximo es seteada en el TRY y al llegar al loop dice que la variable no existe :S

alguien podria ayudarme? :P

gracias, saludos
  #2 (permalink)  
Antiguo 20/03/2009, 11:28
venkman
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: error? ayuda :/

El problema es que la estás declarando dentro del try y así sólo se ve dentro del try. Declárala primero en el alcance donde deba existir.
  #3 (permalink)  
Antiguo 20/03/2009, 11:34
 
Fecha de Ingreso: diciembre-2006
Mensajes: 60
Antigüedad: 17 años, 4 meses
Puntos: 0
Respuesta: error? ayuda :/

esque si la declaro afuera va a retornar error y hasta ahí llega la aplicacion :S
  #4 (permalink)  
Antiguo 20/03/2009, 11:50
Avatar de drac94  
Fecha de Ingreso: mayo-2008
Ubicación: México
Mensajes: 383
Antigüedad: 15 años, 11 meses
Puntos: 5
Respuesta: error? ayuda :/

una cosa es la declaracion y otra muy diferente la inicializacion, lo que dice venkman es correcto tienes que declararla afuera para que la puedas usar valga la redundancia afuera

asi:
Código PHP:
int proximo=0;
        try{
            
proximo scanner.nextInt();
            if(
proximo>=100 || proximo==0){
                throw new 
Exception();
            }
        }catch(
Exception e){
            
System.out.println("Debes ingresar un valor del tipo int (del 1 al 100)");
            
System.exit(0);
        }
        for(
int i=0;i>=proximo;int++;){

        }
        
html.close(); 
  #5 (permalink)  
Antiguo 20/03/2009, 12:04
 
Fecha de Ingreso: diciembre-2006
Mensajes: 60
Antigüedad: 17 años, 4 meses
Puntos: 0
Respuesta: error? ayuda :/

Cita:
Iniciado por drac94 Ver Mensaje
una cosa es la declaracion y otra muy diferente la inicializacion, lo que dice venkman es correcto tienes que declararla afuera para que la puedas usar valga la redundancia afuera

asi:
Código PHP:
int proximo=0;
        try{
            
proximo scanner.nextInt();
            if(
proximo>=100 || proximo==0){
                throw new 
Exception();
            }
        }catch(
Exception e){
            
System.out.println("Debes ingresar un valor del tipo int (del 1 al 100)");
            
System.exit(0);
        }
        for(
int i=0;i>=proximo;int++;){

        }
        
html.close(); 
pero si hago eso, al volver a retomar la variable proximo, tendra el valor ingresado por la consola? o será 0?

:/ en todo caso ya funcionó, ahora el problema es con el loop O.o
me tiene desesperado, alguna manito? :P
Código:
import java.io.*;
import java.net.URL;
import java.util.Scanner;


/**
 *
 * @author Juan Pablo Tosso
 * @version 0.5 - Beta
 * @since marzo del 2009
 * @nota este software a sido programado con propositos educativos. El autor no se hace responsable por el uso que se le de.
 */
public class Main  {


    public static String ask;
    public static void main(String[] args) throws IOException {

Scanner scanner = new Scanner(System.in);
System.out.println("Bienvenido!\n\n");
System.out.println("Ingrese una opcion:\n0: Cerrar Software.\n1: Proceder a injectar sitio.\n2: Analizar multiples sitios.\n");

     int next = scanner.nextInt();


switch (next){
    case 0:
        System.out.println("\n\nGracias por usar JInjector, el programa se cerrara en 5 segundos...\nhttp://www.eljuampi.net");
             try {
            Thread.sleep(1000);
            System.out.println("5...");
            Thread.sleep(1000);
            System.out.println("4...");
            Thread.sleep(1000);
            System.out.println("3...");
            Thread.sleep(1000);
            System.out.println("2...");
            Thread.sleep(1000);
            System.out.println("1...\n http://www.eljuampi.net");
            
       }
     catch (InterruptedException e) {
       e.printStackTrace();
       }
        System.exit(0);
        break;
    case 1:
        System.out.println("\nPor favor ingresa el sitio que deseas analizar(http://example.com/file.php?foo=):\n");
        ask = scanner.next();
        if(!ask.endsWith("=") || !ask.startsWith("http://")){
            System.out.println("\nDebes ingresar una URL correctamente!!");
            System.exit(0);
        }
        System.out.println("URL correcta, prosediendo a comprobar estado del servidor...\n\n");
        URL url = new URL(ask);
        try{
            if(url.openConnection().getContentLength()>=0){
            System.out.println("El sitio no se encuentra disponible.");
            System.exit(0);
        }
        }catch(Exception e){
           System.out.println("Error");
        }
        
        System.out.println("Sitio encontrado, cargando...\n");
        BufferedReader html = new BufferedReader(new InputStreamReader(url.openStream()));
        System.out.println("Sitio cargado exitosamente! \n ¿Desea revisar si el sitio es vulnerable? (si/no)\n");
        String pregunta = scanner.next();
        if(pregunta.equals("si")){
            /*Procedemos a analizar cada linea...*/
               String rawdata;
               Boolean funco = true;
               while((rawdata = html.readLine()) != null){
                   if(rawdata.contains("mysql_fetch_") || rawdata.contains("You have an error in your SQL syntax") || rawdata.contains("mysql_num_rows") || rawdata.contains("Division by zero in")){
                       funco = false;
                   }
               }
               if(funco){
                   System.out.println("Sitio aparentemente vulnerable =)");
               }else{
                   System.out.println("Sitio aparentemente no vulnerable =(");
               }
        }else{
            System.out.println("Escaneo de vulnerabilidades abortado\n");
        }
        System.out.println("Se iniciara el conteo de columnas, porfavor indique el maximo de columnas a buscar (maximo 100)");
        int proximo = 0;
        try{
            proximo = scanner.nextInt();
            if(proximo>=100 || proximo==0){
                throw new Exception();
            }
        }catch(Exception e){
            System.out.println("Debes ingresar un valor del tipo int (del 1 al 100)");
            System.exit(0);
        }
          for(int i=0;i>=proximo;i++;){
System.out.println(i);
       }
        html.close();
        break;
}

}
  #6 (permalink)  
Antiguo 20/03/2009, 12:19
venkman
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: error? ayuda :/

En el bucle tienes i mayor o igual que proximo. Debería ser i menor o igual que proximo.
  #7 (permalink)  
Antiguo 20/03/2009, 15:57
 
Fecha de Ingreso: diciembre-2006
Mensajes: 60
Antigüedad: 17 años, 4 meses
Puntos: 0
Respuesta: error? ayuda :/

for(int i=0;i<=proximo;i++){
//loop...
}

arreglado, gracias =)
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 19:26.