fork(6) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. // Main method
  11. public static void main(String[] args)
  12. {
  13. // Create a new scanner
  14. Scanner input = new Scanner(System.in);
  15.  
  16. // Set array list
  17. int[] tempList = new int[7];
  18.  
  19. // Prompt user for input and store input
  20. System.out.println("Enter the hightest temperature of each day for a week (starting on Sunday): ");
  21. for(int i = 0; i < tempList.length; i++)
  22. tempList[i] = input.nextInt();
  23.  
  24. // Averages temperature
  25. double avgTemp = avgTemp(tempList);
  26. System.out.printf("The average temperature of the week is: %.2f degree %n", avgTemp);
  27.  
  28. // Display hottest temperature
  29. int maxTemp = maxTemp(tempList);
  30. System.out.println("The highest temperature of the week is: " + maxTemp + " degree");
  31.  
  32. // Display coldest temperature
  33. int minTemp = minTemp(tempList);
  34. System.out.println("The coldest temperature of the week is: " + minTemp + " degree");
  35.  
  36.  
  37. int[] maxTempList = searchTemp(tempList, maxTemp);
  38.  
  39. for(int i = 0; i < maxTempList.length; i++){
  40. System.out.print("The hottest days of the week are: " +maxTempList[i]);
  41.  
  42. System.out.print(weekDay(tempList,maxTemp));
  43. }
  44. }
  45.  
  46. // Average the temperature
  47. public static double avgTemp(int[] array)
  48. {
  49. int tempTotal = array[0];
  50.  
  51. // Total temperature values
  52. for(int i = 0; i < array.length; i++)
  53. tempTotal = array[i]+tempTotal;
  54.  
  55. // Return temperature average.
  56. return ((double)tempTotal/array.length);
  57. }
  58.  
  59. // Get hottest temperature
  60. public static int maxTemp(int[] array)
  61. {
  62. int max = array[0];
  63.  
  64. // Check and replace max temp
  65. for(int i = 1; i < array.length; i++){
  66. if(max < array[i])
  67. max = array[i];
  68.  
  69. }
  70. return max;
  71. }
  72.  
  73. // Get coldest temperature
  74. public static int minTemp(int[] array)
  75. {
  76. int min = array[0];
  77. for(int i = 1; i < array.length; i++){
  78. if(min > array[i])
  79. min = array[i];
  80. }
  81. return min;
  82. }
  83.  
  84.  
  85. // Return days
  86. public static String weekDay(int i, int[] array)
  87. {
  88. int[] displayWeekDay = searchTemp(array, i);
  89.  
  90. for(i = 0; i < displayWeekDay.length; i++){
  91.  
  92. String weekDay = "";
  93. switch(i)
  94. {
  95. case 0: return "Sunday";
  96. case 1: return "Monday";
  97. case 2: return "Tuesday";
  98. case 3: return "Wednesdays";
  99. case 4: return "Thursday";
  100. case 5: return "Friday";
  101. case 6: return "Saturday";
  102. }
  103. }
  104. return weekDay;
  105. }
  106.  
  107.  
  108. // Finds the index of the hottest/coldest days
  109. public static int[] searchTemp(int[] temp, int key)
  110. {
  111. int count = 0;
  112. for(int i = 0; i < temp.length; i++){
  113. if(temp[i] == key)
  114. count++;
  115. }
  116.  
  117. int[] index = new int[count];
  118. for(int j = 0; j < index.length; j++){
  119. for(int i = 0; i < temp.length; i++){
  120. if(temp[i] == key){
  121. if(j > 0 && index[j - 1] == i)
  122. continue;
  123. else{
  124. index[j] = i;
  125. break;
  126. }
  127. }
  128. }
  129. }
  130. return index;
  131. }
  132. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:42: error: incompatible types: int[] cannot be converted to int
		System.out.print(weekDay(tempList,maxTemp));
		                         ^
Main.java:104: error: cannot find symbol
		return weekDay;
		       ^
  symbol:   variable weekDay
  location: class Ideone
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
2 errors
stdout
Standard output is empty