Java- Program is not showing output

时间:2015-07-28 16:36:02

标签: java output

I am new to Java and I am currently making a program that shows yearly total and average for two years, The problem is that it does not showing any output and I don't know why, can anybody help me? Thank you.

import java.util.Scanner;

public class Main {

  static Scanner in = new Scanner(System.in);

  public static void main(String[] args) {
    String[] months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
    double[] monthlyIncomes = new double[12];
    String[] months2015 = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
    double[] monthlyIncomess = new double[12];
    double total = 0;
    double average = 0;
    double max = 0;
    double min = 0;
    double n;

    for (int i = 0; i < monthlyIncomes.length; i++) {
        System.out.println("Enter income for " + months[i] + " 2014 :");
        monthlyIncomes[i] = in.nextDouble();
    }
    for (int i = 0; i < monthlyIncomess.length; i++) {
        System.out.println("Enter income for " + months2015[i] + " 2015 :");
        monthlyIncomess[i] = in.nextDouble();
    }
  }

  static void Max(double n, double max, double min, double [] monthlyIncomes) {
     for (int i = 0; i < monthlyIncomes.length; i++) {
         if (monthlyIncomes[i] > max) {
             max = monthlyIncomes[i];
         }
     }
     max = in.nextDouble();
    System.out.println("Largest income is: " + max );
  }


  static void Min(double n, double max, double min, double [] monthlyIncomes) {
    for (int i = 0; i < monthlyIncomes.length; i++){
        if (monthlyIncomes[i] < min) {
            min = monthlyIncomes[i];
        }
    }
    min = in.nextDouble();
    System.out.println("Smallest income is: " + min);
  }

  static void total(double total, double [] monthlyIncomes) {
    for (int i = 0; i < monthlyIncomes.length; i++)
    total = total + monthlyIncomes[i];
    total = in.nextDouble();
    System.out.println("The total is : " + total);
  }

  static void average(double average,double total, double [] monthlyIncomes) {
    for (int i = 0; i < monthlyIncomes.length; i++)
        average = total/12;
    average = in.nextDouble();
    System.out.println("The average income is :" + average);
  }

  static void max(double max, double [] monthlyIncomes2015) {
    for (int i = 0; i < monthlyIncomes2015.length; i++) {
        if (monthlyIncomes2015[i] > max) {
            max = monthlyIncomes2015[i];
        }
    }
    max = in.nextDouble();
    System.out.println("The largest income for 2015 is :" + max);
  }

  static void min(double min, double [] monthlyIncomes2015) {
    for (int i = 0; i < monthlyIncomes2015.length; i++) {
        if (monthlyIncomes2015[i] < min){
            min = monthlyIncomes2015[i];
        }
    }
    min = in.nextDouble();
    System.out.println("The smallest income for 2015 is :" + min);
  }

  static void total2(double total, double [] monthlyIncomess) {
    for (int i = 0; i < monthlyIncomess.length; i++)
        total = total + monthlyIncomess[i];
    total = in.nextDouble();
    System.out.println("The total for 2015 is : " + total);
  }

  static void average2(double total, double average, double [] monthlyIncomess) {
    for (int i = 0; i < monthlyIncomess.length; i++)
        average = total/12;
    average = in.nextDouble();
    System.out.println("The average income is :" + average);
  }
}

2 个答案:

答案 0 :(得分:1)

The problem is that the main() is not calling the other functions like max min avg and total

答案 1 :(得分:0)

The reason is that you haven't invoke your other methods in your main method,so that your program stops after getting the values on main method.