Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can someone please help me keep the contents of this program but code it differe

ID: 3545514 • Letter: C

Question

Can someone please help me keep the contents of this program but code it differently? I prefer to have the main in the bottom                    and function up top...

import java.util.Scanner;

public class integersSum {

       public static void main(String[] args) {

              Scanner input=new Scanner (System.in);

              System.out.println("Amount of numbers to be entered ?");

              int x;

              x=input.nextInt();

              System.out.println("Enter "+x+" number, one per line:");

              int []ar =new int[x];

              for(int i=0;i<x;i++)

              ar[i]=input.nextInt();

              total(ar,x);

       }

       

       public static void total(int a[],int n)

       {

              

              int sum=0;

              for(int i=0;i<n;i++)

              {sum+=a[i];

                     }

              System.out.println("Sum "+sum+".");

              System.out.println("Numbers :");

              for(int i=0;i<n;i++)

                     System.out.println(a[i]+"which is "+(float)a[i]*100/sum+"% of the sum.");

       }

}

Explanation / Answer

import java.util.Scanner;

public class integersSum {

public static void total(int a[],int n)

{

int sum=0;

for(int i=0;i<n;i++)

{sum+=a[i];

}

System.out.println("Sum "+sum+".");

System.out.println("Numbers :");

for(int i=0;i<n;i++)

System.out.println(a[i]+"which is "+(float)a[i]*100/sum+"% of the sum.");

}

public static void main(String[] args) {

Scanner input=new Scanner (System.in);

System.out.println("Amount of numbers to be entered ?");

int x;

x=input.nextInt();

System.out.println("Enter "+x+" number, one per line:");

int []ar =new int[x];

for(int i=0;i<x;i++)

ar[i]=input.nextInt();

total(ar,x);

}


}