Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.

Paste

Pasted as Plain Text by Collins ( 11 years ago )
public class DataList {

 private ArrayList<Integer> intListe = new ArrayList<Integer>();

 public DataList(ArrayList<Integer> list) {
  this.intListe = list;
 }

 // TODO!
 public DataList(String filename) {
  File file = new File&#40;filename&#41;;
  Scanner sc = null;
  try {
   sc = new Scanner(file);
  } catch (FileNotFoundException f) {
   System.out.println("Datei " + file + " nicht vorhanden");
  }
  while (sc.hasNextLine()) {
   String line = sc.nextLine();
   line = line.trim();// Leerzeichen am Anfang und Ende entfernen
   if (line.length() == 0 || line.charAt(0) == '%') {
    continue;
   }
   int zahl = Integer.parseInt(line);
  }
  sc.close();
 }

 public ArrayList<Integer> getAbsoluteValue() {
  ArrayList<Integer> neueListe = new ArrayList<Integer>();
  for (Integer i : intListe) {
   neueListe.add((int) Math.sqrt(Math.pow(i, 2)));
  }
  return neueListe;
 }

 public int getMax() {
  int max = 0;
  for (Integer i : intListe) {
   if (i > max) {
    max = i;
   }
  }
  return max;
 }

 public int getMin() {
  int min = intListe.get(0);
  for (Integer i : intListe) {
   if (i < min) {
    min = i;
   }
  }
  return min;
 }

 public int getNumber(int min) {
  int zaehler = 0;
  for (Integer i : intListe) {
   if (i > min) {
    zaehler++;
   }
  }
  return zaehler;
 }

 public int[] getMaxPositions() {
  int[] maxStellen = new int[intListe.size()];
  for (int i = 0; i < intListe.size(); ++i) {
   if (intListe.get(i) == getMax()) {
    for (int j = 0; j < maxStellen.length; j++) {
     maxStellen[j] = i;
    }
   }
  }
  return maxStellen;
 }

 public String getRange() {
  String bereich = "<";
  for (Integer i : intListe) {
   if (i == getMin()) {
    bereich += i;
   }
  }
  return bereich;
 }
}

 

Revise this Paste

Parent: 59815
Your Name: Code Language: