Advertisement
Guest User

Saving Values to an Array

a guest
Nov 18th, 2019
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Messwerte_ {
  4.    
  5.     public static void main(String[] args) {
  6.    
  7.     double result = 0.0;
  8.     double[] Arrayspeicher = {result};
  9.     int Messwert = inputCheck();
  10.     for (int i = 1; i <= Messwert; i++)
  11.     {
  12.         double upper    = 27;
  13.         double lower   = -16;
  14.         result = Math.random() * (upper - lower) + lower;
  15.         result = Math.round(result*100.0)/100.0;
  16.         //System.out.println("Messwert " + i + ": " +  result);
  17.        
  18.        
  19.         Arrayspeicher = new double[] {result};
  20.        
  21.         System.out.println("Messwert " + i + ": " +  Arrays.toString(Arrayspeicher));
  22.  
  23.         }
  24.        
  25.         Arrays.sort(Arrayspeicher);
  26.         System.out.println(Arrays.toString(Arrayspeicher));
  27.  
  28. }
  29.  
  30. public static int inputCheck() {
  31.  
  32.     Scanner keyboard = new Scanner(System.in);
  33.     System.out.print("Bitte geben Sie eine Ziffer ein die höher gleich 5 und niedriger gleich 40 ist: ");
  34.     int Messwert = keyboard.nextInt();
  35.     System.out.println();
  36.  
  37.     while (Messwert < 4 || Messwert > 41) {
  38.        
  39.     }
  40.     return Messwert;  
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement