viernes, 21 de octubre de 2011

Arreglos - Java

 1 package arreglos;
 2 import java.io.*;
 3 
 4 public class Main {
 5 
 6     public static void main(String[] args)throws IOException {
 7         String arreglo[]= new String [20];
 8 
 9          arreglo[1]= "hola como estas";
10          arreglo [2]= "bien y tu";
11         System.out.println(arreglo[1]);
12      String palabras="hola como estas";
13         System.out.println(palabras);
14         String mio[]= new String[palabras.length()];
15         for(int i =0;i<palabras.length();i++){
16             mio[i]=palabras.substring(i,i+1);
17             System.out.print(mio[i]);
18         }
19         System.out.println("\n");
20         String Texto;
21         //crear un programa que lea numero determinado de numeros
22         //y que imprima el promedio de numeros
23         //la condicion de termino es cuando numero = 0
24         System.out.println("Ingrese los numeros que desea promediar");
25    InputStreamReader IRS = new InputStreamReader(System.in);
26    BufferedReader tex =new BufferedReader(IRS);
27    Texto= tex.readLine();
28    String arreglin[]= new String[Texto.length()];
29    Integer num[]=new Integer[Texto.length()];
30    int acu=0;
31    for(int i=0;i<Texto.length();i++){
32 
33        arreglin[i]=Texto.substring(i,i+1);
34 
35        }
36 
37    for(int i=0;i<Texto.length();i++){
38       
39        num[i]=Integer.parseInt(arreglin[i]);
40    }
41    for(int i=0;i<Texto.length();i++){
42        acu = acu+num[i];
43    }
44         System.out.println(acu/Texto.length());
45         int acum=0;
46         int cont = 0;
47         System.out.println("nuevo");
48        Integer nume=0;
49        Texto="";
50 do{
51 
52     Texto = tex.readLine();
53     
54     cont++;
55     nume = Integer.parseInt(Texto);
56     acum= acum+nume;
57   
58 
59 
60 }while(nume==0);
61         System.out.println(acu/(cont-1));
62 
63 
64 
65 
66     }
67 
68 }

No hay comentarios:

Publicar un comentario