• Miércoles 15 de Mayo de 2024, 05:13

Autor Tema:  Identificar el Problema  (Leído 824 veces)

Zyteck

  • Nuevo Miembro
  • *
  • Mensajes: 2
    • Ver Perfil
Identificar el Problema
« en: Miércoles 29 de Septiembre de 2010, 18:36 »
0
Que tal pues tengo un problema con un codigo pero donde este el problema, el problema es que en el metodo de resultados imprime que el arreglo no tiene datos y no se porque. salu2
Código: Java
  1.  
  2.  
  3. import java.util.*;
  4. import java.io.*;
  5.  
  6. public class ArregloADPlus{
  7.  
  8.     double AAD[] = new double[30];
  9.     double copiaAAD[] = new double[30];
  10.     double resp, temp2;
  11.     int modo, MDC, c1=0;
  12.     String temp="";
  13.     Scanner tecla = new Scanner(System.in);
  14.     BufferedReader entrada = new BufferedReader (new InputStreamReader(System.in));
  15.     public static final String CENTINELA = "fin";
  16.  
  17.  
  18. void inicio(){
  19.     System.out.println("Arreglo para ordenar ascendente o descendentemente los valores ingresados");
  20.     }
  21.  
  22.  
  23. void menu(){
  24.    ArregloADPlus AADP = new ArregloADPlus();
  25.  
  26.    System.out.println("Ingrese 1 para modo ascendente o 2 para modo descendente");
  27.    modo = tecla.nextInt();
  28.    if (modo !=1 && modo !=2){
  29.        System.out.println("Ingrese 1 o 2");
  30.        AADP.menu();}
  31.  
  32.     System.out.println("Ingrese como desea introducir los valores");
  33.      System.out.println(" 1)Lectura Por teclado n 2)Por Omisionn 3)Lectura De Archivon 4)Aleatorion");
  34.      MDC = tecla.nextInt();
  35. }
  36.  
  37.  
  38. void modoCaptura()throws IOException{
  39.     ArregloADPlus AADP = new ArregloADPlus();
  40.     switch(MDC){
  41.         case 1: AADP.teclado();
  42.         break;
  43.         case 2: AADP.omision();
  44.         break;
  45.         case 3: AADP.archivo();
  46.         break;
  47.         case 4: AADP.aleatorio();
  48.         break;
  49.         default:{
  50.             if (MDC<0 || MDC>4)
  51.                 System.out.print("ingrese un valor de 1 al 4n");}
  52.         }
  53. }
  54.  
  55.  
  56. void teclado()throws IOException{
  57.              System.out.println("Ingrese un valor o "fin" para terminar");
  58.              System.out.flush();
  59.              temp = entrada.readLine();
  60.              while(!temp.equals(CENTINELA)){
  61.                  resp = Double.parseDouble(temp);
  62.                  AAD[c1++] = resp;
  63.                  System.out.println("Ingrese una valor o "fin" para terminar");
  64.                  System.out.flush();
  65.                  temp = entrada.readLine();}
  66.              System.arraycopy(AAD,0,copiaAAD,0,AAD.length);
  67. }
  68.  
  69.  
  70. void omision(){
  71.     double AAD1[] = {-26.4,12.6,15,24,78.91,.369,74,14,.1248,7845,6941,1.257425,100,964,-1.36,15485,1000,7895,.137,-9784,4597,12,64,7461,.100,3.14,79.01,963.12,20,457.1};
  72.     System.arraycopy(AAD1,0,AAD,0,AAD1.length);
  73.     System.arraycopy(AAD1,0,copiaAAD,0,AAD1.length);
  74. }
  75.  
  76.  
  77. double archivo() {
  78.     String s, file;
  79.     int i=0;
  80.     Scanner sc=new Scanner(System.in);
  81.     System.out.print("Ingrese la ruta del archivo:");
  82.     file=sc.nextLine();
  83.     System.out.println("Leyendo del archivo:"+file);
  84.     System.out.print("n");
  85.     if(!file.equals("")) {
  86.         try {
  87.             Scanner in=new Scanner(new File(file));
  88.         while(in.hasNextLine()) {
  89.         s=in.nextLine();
  90.         AAD[i++]=Double.parseDouble(s);
  91.             System.out.print(", "+AAD[i-1]);}
  92.             System.arraycopy(AAD,0,copiaAAD,0,AAD.length);
  93.             in.close();
  94.  
  95.         }
  96.         catch (IOException e) {e.printStackTrace();}
  97.         }
  98.     else
  99.         System.out.println("no se pudo abrir el archivo"+file);
  100.         return i;
  101. }
  102.  
  103.  
  104. void aleatorio(){
  105.     for(int c3=0;c3<AAD.length;c3++){
  106.     int tmp=Math.round((float)Math.random()*1000%37767);
  107.     AAD[c3]=(double)tmp;}
  108.     System.arraycopy(AAD,0,copiaAAD,0,AAD.length);
  109. }
  110.  
  111.  
  112. void calcula(){
  113.     if (modo == 1){
  114.         Arrays.sort(AAD);}
  115.     else{
  116.         Arrays.sort(AAD);
  117.         int i,j;
  118.         for(i=0,j=AAD.length -1; i<AAD.length/2;i++,j--){
  119.             temp2=AAD[i];
  120.             AAD[i]=AAD[j];
  121.             AAD[j]=temp2;}
  122.             }
  123. }
  124.  
  125. void resultados(){
  126.     System.out.println("nnLos valores ingresados son:");
  127.     for(int c5=0; c5<AAD.length; c5++){
  128.         System.out.print(copiaAAD[c5]+", ");}
  129.     System.out.println("nnLos valores ingresados ordenados son:");
  130.     for(int c5=0; c5<AAD.length; c5++){
  131.         System.out.print(AAD[c5]+", ");}
  132. }
  133.  
  134.  
  135. public static void main (String args [])throws IOException{
  136.     ArregloADPlus AADP = new ArregloADPlus();
  137.     int r='S';
  138.     AADP.inicio();
  139.     while (r=='s' || r=='S'){
  140.         AADP.menu();
  141.         AADP.modoCaptura();
  142.         AADP.calcula();
  143.         AADP.resultados();
  144.         System.out.println("nnDesea Ordenar otros elementos s/n");
  145.         r=System.in.read();
  146.         System.in.skip(2);}
  147. }
  148. }
  149.  


gracias de antemano