Funciones - import java.io i import java.util p public class Funcionescfw class beginning p public static Scanner teclado = new Scanner(System.in

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.io.*; import java.util.*; i public class Funciones{// class beginning. p public static Scanner teclado = new Scanner(System.in); p /* Métodos */ / /* Función 1: Sumatoria (sqrt(i-2))/(i^2) */ / public static double g(int n){ double acum = 0; for(int i=3; i<=n; i++){ acum+=Math.pow(i-2,0.5)/Math.pow(i,2);} return acum;} r /* Función 2: Multiplicatoria (3n-1) */ / public static int f2(int n){ int acum = 1; for(int i=1; i<=n; i++) acum*=(3*i-1); return acum;} r public static String funcion2(int n){ String s = ""; int acum = 1; for(int i=1; i<n; i++){ acum=(3*i-1); s+=acum + " * ";} return s+n+" = "+f2(n);} r /* Función 3: Serie suma de pares y resta de impares */ / public static int f3(int n){ int acum = 0; int i = 1; while(i<=n){ if(i%2 == 0) acum+=i; else acum-=i; i++;} return acum;} r public static String funcion3(int n){ String s= ""; int acum = 0; int i = 1; while(i<n){ if(i%2 == 0) s+=i+" - ";
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
else s+=i+" + "; i++;} return "- "+s+n+" = "+f3(n);} r /* Función 4 */ / public static int f4(int n){
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/29/2009 for the course ITC TC-1002 taught by Professor X during the Spring '09 term at ITESM.

Page1 / 3

Funciones - import java.io i import java.util p public class Funcionescfw class beginning p public static Scanner teclado = new Scanner(System.in

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online