Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.text.DecimalFormat;
- import java.util.Scanner;
- public class Ass08ID6120
- {
- public static void main(String [] args)
- {
- int size, total;
- Scanner arraysize = new Scanner(System.in);
- System.out.println("How many numbers will you enter?");
- size = arraysize.nextInt();
- int[] a = new int[size];
- System.out.println("Enter " + size + " integers, one per line:");
- for(int v = 0; v <a.length; v++)
- {
- int x;
- x = arraysize.nextInt();
- a[v] = x;
- }
- total = totalarray(a);
- System.out.println("The sum is: " + total);
- System.out.println("The numbers are:");
- percentage(a, total);
- //part 2 palindrome
- }
- private static int totalarray(int[] a)
- {
- int t = 0;
- for(int y = 0; y <a.length; y++)
- {
- t += a[y];
- }
- return t;
- }
- public static void percentage(int[] s, int t)
- {
- double percent;
- DecimalFormat numberFormat = new DecimalFormat("#.0000");
- for(int h = 0; h <s.length; h++)
- {
- percent = (s[h] / ((double)t)) * 100;
- System.out.println(s[h] + ", which is " + numberFormat.format(percent) + "% of the sum.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement