fork 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. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. double[] array = {1, 2, 3, 4, 5, 4, 3, 2, 1, 7};
  13. File path = new File("path");
  14. File file = new File(path, "my_file-name.txt");
  15. // String filename = "my_file";
  16. FileOutputStream outputStream;
  17.  
  18. try {
  19. //outputStream = new FileOutputStream(file); //openFileOutput(file, Context.MODE_APPEND);
  20. double peak1, peak2;
  21. if(array.length >= 2) {
  22. peak1 = array[0];
  23. peak2 = array[1];
  24. } else {
  25. return;
  26. }
  27. for (double d : array) {
  28. if(peak1 < peak2 && d > peak1) {
  29. peak1 = d;
  30. } else if(d > peak2) {
  31. peak2 = d;
  32. }
  33. String s = Double.toString(d) + ",";
  34. //outputStream.write(s.getBytes());
  35. }
  36.  
  37. String newline = "/n";
  38. //outputStream.write(newline.getBytes());
  39.  
  40. //outputStream.close();
  41. System.out.println("Peaks: " + peak1 + " ; " + peak2);
  42. } catch (Exception e) {
  43. System.out.println("Error: " + e);
  44. //e.printStackTrace();
  45. }
  46. }
  47. }
Success #stdin #stdout 0.1s 27940KB
stdin
Standard input is empty
stdout
Peaks: 7.0 ; 5.0