Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.99 KB | None | 0 0
  1.    
  2.    static int antal;
  3.    
  4.     public static void main(String[] args){
  5.        
  6.         double[] tid = new double[100];
  7.         inTid(tid);
  8.         utTid(tid);
  9.        
  10.         snabbastTid(tid);
  11. }
  12.  
  13.  
  14. public static void inTid(double[] tid){
  15.     Scanner input = new Scanner(System.in);
  16.     System.out.println("Skriv in tiderna. Avsluta med 0.");
  17.     antal = 0;
  18.     double temp = input.nextDouble();
  19.     while (temp != 0) {        
  20.         tid[antal] = temp;
  21.         antal++;
  22.         temp= input.nextDouble();
  23.     }
  24.    
  25. }
  26. public static void utTid(double[] tid){
  27.     System.out.print("Tiderna är: ");
  28.     for (int i = 0; i < antal; i++) {
  29.         System.out.print(" " + tid[i]);
  30.     }
  31.     System.out.println();
  32.    
  33. }
  34.  
  35. public static void snabbastTid(double[] tid)
  36. {
  37.     double temp = tid[0];
  38.     for (int i = 0; i < tid.length; i++) {
  39.         if(temp > tid[i] && tid[i] != 0)
  40.             temp = tid[i];
  41.     }
  42.     System.out.print(temp + " är den snabbaste tiden");
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement