Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: I have several errors when compiling my code as the name help

  1. #1
    Junior Member
    Join Date
    May 2019
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy I have several errors when compiling my code as the name help

    [ATTACH]3581[/ATTACH]
     
    import java.util.Scanner;
    public class Arreglos {
    	public static int [ ] llenarArreglo ( int elementos ) {
    		int i; int [ ] v; 
    		v = new int [ elementos ];
    		Scanner sc = new Scanner ( System.in );
     
    		for ( i = 0; i < elementos; i++ ) {
    			System.out.print ( "v [ " + i + " ] = " );
    			v [ i ] = sc.nextInt ( ); 
    		}
     
    		return v;
    	}
     
    	public static double promedio ( int [ ] v ) {
    		double prom = 0.0;
    		for ( int i = 0; i < v.length; i++ )
    			prom += v[i];
     
    		return prom / ( double ) v.length;	
    	}
     
    	public static double desviacion ( int [ ] v ) {
    		double prom, sum = 0; int i, n = v.length;
    		prom = promedio ( v );
     
    		for ( i = 0; i < n; i++ ) 
    			sum += Math.pow ( v [ i ] - prom, 2 );
     
    		return Math.sqrt ( sum / ( double ) n );
    	}
     
    	// 0 - Menor a Mayor, 1 - Mayor a menor
    	public static int [ ] burbuja ( int [ ] v, int ord ) {
    		int i, j, n = v.length, aux = 0;
     
    		for ( i = 0; i < n - 1; i++ )
    			for ( j = i + 1; j < n; j++ )
    				if ( ord == 0 )
    					if ( v [ i ] > v [ j ] ) {
    						aux = v [ j ];
    						v [ j ] = v [ i ];
    						v [ i ] = aux;
    					}
    				else if ( ord == 1 )
    					if ( v [ i ] < v [ j ] ) {
    						aux = v [ i ];
    						v [ i ] = v [ j ];
    						v [ j ] = aux;
    					}
     
    		return v;
    	}
     
    	public static double mediana ( int [ ] v ) {
    		int pos = 0, n = v.length;
    		double temp = 0, temp0 = 0;		
    		// ordenar de menor a mayor
    		v = burbuja ( v, 0 );
     
    		temp = n / 2;
    		if ( n % 2 == 0 ) {
    			pos = (int)temp;			
    			temp0 = (double)(v [ pos ] / v [ pos + 1 ]);
    		}
    		if ( n % 2 == 1 ) {
    			pos = (int)(temp + 0.5);
    			temp0 = (double)(v [ pos ]);	
    		}
     
    		return temp0;
    	}
     
    	public static int rango ( int [ ] v ) {
    		// ordenar de mayor a menor
    		v = burbuja ( v, 1 );
     
    		return v [ v.length - 1 ] - v [ 0 ];
    	}
     
    	public static int moda ( int [ ] v ) {
    		int i, j, moda = 0, n = v.length, frec;
    		int frecTemp, frecModa = 0, moda1 = -1; 
     
    		// ordenar de menor a mayor
    		v = burbuja ( v, 0 );
     
    		for ( i = 0; i < n; i++ ) {
    			frecTemp = 1; 
    			for ( j = i + 1; j < n; j++ ) {
    				if ( v [ i ] == v [ j ] )
    					frecTemp++;
    			}
    			if ( frecTemp > frecModa ) {
    				frecModa = frecTemp;
    				moda1 = v [ i ];
    			}
    		}
    		return moda1;
    	}
     
    	public static void reportaVector ( int [ ] v ) {
    		for ( int i = 0; i < v.length; i++ )
    			System.out.print ( v [ i ] + " " );
    		System.out.println ( "" );
    	}
     
     
    	public static void main ( String [ ] args ) {
    		int n; int [] v;
    		double media, mediana, moda, rango, desviacion;
    		Scanner sc = new Scanner ( System.in );
    		System.out.println ( "Dimension Arreglo : ");
    		n = sc.nextInt ( );
     
    		v = llenarArreglo ( n );
     
    		//Media
    		media = promedio ( v );
    		//Mediana
    		mediana = mediana ( v );		
     
    		//Moda
    		moda = moda ( v );
     
    		//Rango
    		rango = rango ( v );			
     
    		//Desviacion
    		desviacion = desviacion ( v );
     
    		System.out.println ( " Moda del vector: " + moda);
    		System.out.println ( " Media del vector: " + media);
    		System.out.println ( " Mediana del vector: " + mediana);
    		System.out.println ( " Rango del vector: " + rango);
    		System.out.println ( " Desviacion del vector: " + desviacion);
     
    		reportaVector ( v );
    	}

  2. #2
    Member John Joe's Avatar
    Join Date
    Jun 2017
    Posts
    277
    My Mood
    Amused
    Thanks
    8
    Thanked 19 Times in 19 Posts

    Default Re: I have several errors when compiling my code as the name help

    What error?
    Whatever you are, be a good one

  3. #3
    Junior Member
    Join Date
    May 2019
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Re: I have several errors when compiling my code as the name help

    Quote Originally Posted by John Joe View Post
    What error?
    does not want me to compile the code gives me error in the name help bro.

  4. #4
    Member John Joe's Avatar
    Join Date
    Jun 2017
    Posts
    277
    My Mood
    Amused
    Thanks
    8
    Thanked 19 Times in 19 Posts

    Default Re: I have several errors when compiling my code as the name help

    can you post the error?
    Whatever you are, be a good one

Similar Threads

  1. [SOLVED] Errors when compiling with an object
    By Inked. in forum Object Oriented Programming
    Replies: 6
    Last Post: May 12th, 2014, 01:46 PM
  2. Replies: 7
    Last Post: May 8th, 2014, 12:51 PM
  3. my code is not compiling
    By kittykat0953 in forum What's Wrong With My Code?
    Replies: 13
    Last Post: February 4th, 2014, 05:18 PM
  4. Replies: 3
    Last Post: April 27th, 2013, 07:19 AM
  5. Replies: 3
    Last Post: March 6th, 2012, 03:50 AM

Tags for this Thread