import java.util.*;
public class temp
    public static void main (String[] args)
//Declear variables
int LowT=0, HighT=0, high, low, RangeT=0, zip, k, d, i;
double Avg, HighAvg=0, LowAvg=0, RangeAvg=0;

//New Scanner
Scanner input = new Scanner(;
//Informs user on what the program does
System.out.println("This program calculates highest, lowest and average daily temperatures.");
//Ask user for zip

//array to get months
String[] day= {"Monday", "Tuesday", "Wensday", "Thursady", "Friday", "Saturday", "Sunday"};
//Arrays for high low and ranges
    int[]highest = new int [d];
        int[]lowest = new int [d];
        int[]ranges = new int [d];
//Ask for highest and lowest temp for each month
System.out.println("Enter the highest and lowest temperature values");
//loop to get average temps
for (k=0; k<d; k++)
    System.out.print("Enter average high for " +day[k]+" ");
    System.out.print("Enter the average low for " +day[k]+" ");


//header format
String formathd = "      Day        Highs        Lows        \n";
        String dashes ="    ------       -----         ----       \n";
//Print headers
String formattable= ("%10s     %6d    %9d    \n");
//loop to output information recieved from user
for (k=0; k<d; k++)
System.out.printf(formattable, day[k], highest [k], lowest [k], ranges [k]);    

//variables decleared for highest and lowest month
String hhday =" ";
String hlday =" ";
String hrday =" ";
String lhday =" ";
String llday =" ";
String lrday =" ";
//loop find highest,lowest and range of the temps
for (k=0; k<3; k++) //For loop to get high , low, and avg
    if (k==0) //if loop to get high value and work with it
    Avg= Mean(highest, d);
        high= High(highest, d); 
        low= Low(highest, d);
        HighAvg= Avg;
    hhday= day [high];
        lhday= day [low];

        if (k==1) //If loop to get lowest value 
    Avg =Mean(lowest, d);
        high= High(lowest, d);  
        low= Low(lowest, d);
        LowAvg= Avg;
    hlday= day [high];
        llday= day [low];

        if (k==2)  //If loop to get average 
    Avg =Mean(ranges, d);
        high= High(ranges, d);  
        low= Low(ranges, d);
    hrday= day [high];
        lrday= day [low];
//Format for results 

    String dailyAvg = "Daily Average";
    String Highday = "Highest Day";
    String Lowday = "Lowest Day";

System.out.print(dailyAvg+"    "+HighAvg+"   "+LowAvg+"    \n"); 
System.out.printf(Highday+"      "+hhday+"     "+hlday+"    "+hrday+"\n");
System.out.printf(Lowday+"   "+lhday+"     "+llday+"    "+lrday+"\n");

//Method for mean
public static double Mean (int[] swap, int i)
    double tSwap=0;
    double Avg=0;

    for (int k=0; k<i; k++) //For loop to add up all numbers
    tSwap = tSwap+swap[k];
    Avg = (double)(tSwap) / i; //Equation to get overall average
    return Avg;
//Method for highest day
public static int High(int[] swap, int i)
    int position = 0, greatest = swap [0];
    for (int k=0; k<i; k++) //For loop to get the greatest number
    if (swap[k]>greatest)
    greatest=swap [k];
    if(greatest == swap[k])
    position = k;
    return position;
//Method for lowest day
public static int Low(int[] swap, int i)
    int position=0, least=swap [0]; //Declear variables
    for (int k=0; k<i; k++) // For loop to determine lowest number
    if(swap [k]<least)
    least = swap [k];
    if(least == swap [k])
    position = k;
    return position;

it is in the daily average for the high and low average i just want to reduce so i can align the table

Recommended Answers

All 4 Replies

you want to reduce a decimal ?

myDecimal -= 1;

where should that go

this is the outcome i get

     Day        Highs        Lows        
    ------       -----         ----       
    Monday         68           55    
   Tuesday         70           56    
   Wensday         52           40    
  Thursady         70           62    
    Friday         55           42    
  Saturday         51           40    
    Sunday         52           36    
Daily Average    59.714285714285715   47.285714285714285           
Highest Day      Thursady     Thursady    
Lowest Day       Saturday      Sunday   

i wanna reduce the decimal place in the daily average..

which has nothing to do with "reducing a decimal".
this tutorial shows everything you need to know.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.