You are on page 1of 6

GUIA NUMERO 4 01. /* * To change this template, choose Tools | Templates * and open the template in the editor.

*/ package guia4; import java.io.*; /** * * @author SENA */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here BufferedReader br= new BufferedReader (new InputStreamReader (System.in)); try{ int i,acum; acum=0; for(i=1; i<=10; i++){ acum=acum+i; } System.out.println("EL RESULTADO ES: "+acum);

}catch(Exception e){}

} 2. /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package guia4; import java.io.*; /** * * @author SENA

*/ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here int i,acun=0; BufferedReader br= new BufferedReader (new InputStreamReader (System.in)); try{ for(i=0;i<=10;i++) { if(i%2==0) { acun=acun+i; } } System.out.println("LA SUMA DE LOS 5 PRIEMROS NUMEROS PARES ES: "+acun); }catch(Exception e){}

} 3. /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package guia4; import java.io.*; /** * * @author SENA */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here int i,n; BufferedReader br= new BufferedReader (new InputStreamReader (System.in));

try{ System.out.println("DIGITE LA CANTIDAD DE NUMEROS "); n=Integer.parseInt(br.readLine()); int num, sum=0; for(i=1;i<=n;i++) { System.out.println("DIGITE NUMERO "+i); num=Integer.parseInt(br.readLine()); if(num%2!=0) { sum=num+sum; } } System.out.println("LA SUMA ES: "+sum);

}catch(Exception e){}

} 4. /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package guia4; import java.io.*; /** * * @author SENA */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here int i,n,f=1; BufferedReader br= new BufferedReader (new InputStreamReader (System.in)); try{

System.out.println("DIGITE UN NUMERO "); n=Integer.parseInt(br.readLine()); for(i=1;i<=n;i++){ f=f*i; } System.out.println("EL FACTORIAL ES: "+f);

}catch(Exception e){}

} 5. /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package guia4; import java.io.*; /** * * @author SENA */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here int i,num,cn=0,cp=0; BufferedReader br= new BufferedReader (new InputStreamReader (System.in)); try{ for(i=1;i<=10;i++){ System.out.println("DIGITE NUMERO "+i); num=Integer.parseInt(br.readLine()); if(num<0){ cn++; } if(num>0) cp++;

} System.out.println("CANTIDAD DE NUMEROS NEGATIVOS: "+cn+ "CANTIDAD DE NUMEROS POSITIVOS: "+cp); }catch(Exception e){}

} 6. /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package guia4; import java.io.*; /** * * @author SENA */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here int i,num,sum=0; BufferedReader br= new BufferedReader (new InputStreamReader (System.in)); try{ for(i=1;i<=5;i++){ System.out.println("DIGITE NUMERO "+i+ " NEGATIVO"); num=Integer.parseInt(br.readLine()); if(num<0){ num=num*-1; } if(num%2==0) { sum=sum+num; } } System.out.println("LA SUMA DE LOS PARES ES: "+sum); }catch(Exception e){}

} } 7. /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package guia4; import java.io.*; /** * * @author SENA */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here double i,n,sum=0,promedio; BufferedReader br= new BufferedReader (new InputStreamReader (System.in)); try{ for(i=1;i<=5;i++){ System.out.println("DIGITE NUMERO "); n=Double.parseDouble(br.readLine()); sum=sum+n; } promedio=sum/5; System.out.println("EL PROMEDIO ES: "+promedio); }catch(Exception e){}

} 8.

You might also like