practica8

3

Click here to load reader

Upload: geovanny-yungan

Post on 07-Jul-2015

33 views

Category:

Education


0 download

DESCRIPTION

M

TRANSCRIPT

Page 1: Practica8

UNIVERSIDAD NACIONAL DE CHIMBORAZO

FACULTAD DE CIENCIAS DE LA EDUCACION HUMANAS Y

TECNOLOGIAS

NOMBRE: Geovanny Yungan

PRACTICA 8

EJERCICIO 1

Ejercicios con estructura while

1. Generar las siguientes series:

a) 1,2,-3,4,5,-6,7,8,-9,10...n

//GEOVANNY YUNGAN //

package aspractica8;

import java.util.Scanner;

class serie1 {

public static void main(String arg [])

{

Scanner datos=new Scanner(System.in);

int n, i=1, s=0;

System.out.println("*** ingrese un numero**** ");

n=datos.nextInt();

while(i<=n)

{

if(i%3==0)

{

s=i*-1;

}

else

{

s=i;

}

i=i+1;

System.out.print(" " +s+",");

}

}

Page 2: Practica8

}

EJECUCION

EJERCICIO 2

b) 1/2;2/1;3/4;4/3;5/6;6/5;……….n/n+1;n+1/n; // GEOVA//

package jlpractica8;

import java.util.Scanner;

class serie2 {

public static void main(String arg [])

{

Scanner datos=new Scanner(System.in);

int n;

int i=1,s,b,c;

System.out.println("ingrese la cantidad de numeros");

n=datos.nextInt();

i=1;

b=-1;

c=0;

System.out.print("La Serie es:\n");

while(i<=n)

{

if(i%2==0)

{

b=b+2;

s=i/b;

Page 3: Practica8

System.out.print(""+i);

System.out.print("/");

System.out.print(""+ b +",");

}

else

{

c=c+2;

s=i/c;

System.out.print(""+i);

System.out.print("/");

System.out.print(""+c +",");

}

System.out.print(" ");

i=i+1;

}

}

}

EJECUCION