Example.
Input number of array: 3
input array 0 = 5
input array 1 = -5
input array 2 = -5
Output:
3.00 //kai 5+4+3+2+1=15/5= 3.00
-2.00 //kai -5 + -4 + -3 + -2 + -1 + 0 + 1 = 14/7 = -2.00
-2.00 //kai -5 + -4 + -3 + -2 + -1 + 0 + 1 = 14/7 = -2.00
ang pangitaon kai average nila from 1.
heres my codes. help me. tnx.(sorry wrong spelling ang variable na divide sa toDevide wahahaha)
Code:import java.util.*; public class TestProgram { private int input,minus,c=1; private int []array; private static Scanner in = new Scanner(System.in); private double averageFromOne,sum,toDevide=0; public TestProgram(){ askNumberOfInput(); Process(); theOutput(); } public void askNumberOfInput(){ System.out.println("Numer of inputs:" ); setInput(Integer.parseInt(in.nextLine())); setIntArray(new int [getInput()]); } public void Process(){ for(int x=0; x<array.length;x++){ System.out.println("Input a number in array "+x+": "); setInput(Integer.parseInt(in.nextLine())); array[x] = getInput(); } } public void theOutput(){ System.out.println("Output"); for(int x=0; x<array.length; x++){ if(array[x]<=100&array[x]>0){ this.sum = array[x]; for(int y=1; y<=array[x];y++){ this.toDevide++; this.sum += array[x]-y; if(y==array[x]){ System.out.println(sum/toDevide); this.sum =0; this.toDevide=0; } } }else if(array[x]>=-100&array[x]<0){ this.sum = array[x]; for(int y=0; y>=array[x];y--){ //System.out.println("debug"+y); this.toDevide++; this.minus++; if(array[x]<=0){ this.sum+=array[x]+c; //System.out.println("asd"+sum); c++; } if(y==array[x]){ // System.out.println("devide "+toDevide); // System.out.println("sum "+sum); System.out.println(sum/(toDevide+1)); this.sum =0; //<<<run the program w/ the example input above this.toDevide=0; //and see what happens, di na mao ang 3rd output. } //bsag ang sum kai back to zero na, kanang shaded red } } } } public void setInput(int input){ this.input = input; } public int getInput(){ return input; } public void setIntArray(int [] array){ this.array = array; } private int [] getIntArray(){ return array; } public static void main(String args[]){ TestProgram tp = new TestProgram(); } }




Reply With Quote

