|
001 package intermediate;
002
003
004 import java.util.ArrayList;
005
006
007 public class LoopyMortivation
008 {
009
010 /**
011 * @param args
012 */
013 public static void main(String[] args)
014 {
015 int a=5;
016 int b=8;
017 int c=16;
018 //...
019 int z=554;
020
021 int[] group=new int[2600000];//equivalent to declaring 26 variables
022 // for(int index=0; index<group.length; index++)
023 // {
024 // group[index]=(int)(Math.random()*10000);
025 // System.out.println("Generating number "+index+": "+group[index]);
026 // }
027
028 // int index=0;
029 // group[index]=(int)(Math.random()*10000);
030 // while(group[index]!=13)
031 // {
032 // System.out.println("Generating number "+index+": "+group[index]);
033 // index++;
034 // group[index]=(int)(Math.random()*10000);
035 // }
036 // System.out.println("Finally generated 13");
037
038 ArrayList<Integer> numbers=new ArrayList<Integer>();
039 int index=0;
040 numbers.add((int)(Math.random()*10000));
041 while(numbers.get(index)!=13)
042 {
043 System.out.println("Generating number "+index+": "+numbers.get(index));
044 index++;
045 numbers.add((int)(Math.random()*10000));
046 }
047 System.out.println("Finally generated 13");
048
049 int count=0;
050 for(int x: numbers)
051 {
052 //System.out.println("Looking for 14.");
053 if(x==13)
054 {
055 System.out.println("Found one!");
056 count++;
057 }
058 }
059 System.out.println("There are "+count+" 13s");
060
061 int sum=0;
062 for(int x: numbers)
063 {
064 sum+=x;
065 }
066 System.out.println("The sum is "+sum);
067 System.out.println("The average is "+(0.0+sum)/numbers.size());
068
069 int max=numbers.get(0);
070 for(int x: numbers)
071 {
072 if(x>max)
073 max=x;
074 //max=Math.max(max, x);
075 }
076 System.out.println("The max is "+max);
077
078
079 // group[0]=5;
080 // group[1]=8;
081 // group[2]=16;
082 // group[16]=13;
083 // //...
084 // group[25]=554;
085
086 // if(a==13 || b==13 || c==13 //...
087 // || z==13)
088 // {
089 // System.out.println("13 is present.");
090 // }
091 // else
092 // {
093 // System.out.println("13 is not present");
094 // }
095 //
096 // boolean found=false;
097 // for(index=0; index<group.length; index++)
098 // {
099 // if(group[index]==13)
100 // found=true;
101 // }
102 // if(found)
103 // {
104 // System.out.println("13 is present.");
105 // }
106 // else
107 // {
108 // System.out.println("13 is not present");
109 // }
110 // TODO Auto-generated method stub
111
112 }
113
114 }
|