Compare commits
2 Commits
888399464e
...
44d88bb3e7
Author | SHA1 | Date | |
---|---|---|---|
44d88bb3e7 | |||
65f3c0e022 |
@ -1,9 +1,6 @@
|
||||
package Uebungen.Uebung5;
|
||||
|
||||
import java.awt.desktop.SystemSleepEvent;
|
||||
import java.util.Scanner;
|
||||
import java.lang.Character;
|
||||
import java.util.Arrays;
|
||||
public class Aufgabe2 {
|
||||
|
||||
public static void main(String[] args){
|
||||
@ -12,7 +9,7 @@ public class Aufgabe2 {
|
||||
while(true){
|
||||
userInterface();
|
||||
System.out.print("\n\n Check anoter string? [y/N]: ");
|
||||
if(scanner.nextLine().charAt(0)!='y') break;
|
||||
if(scanner.nextLine()!="y") break;
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
@ -23,6 +20,7 @@ public class Aufgabe2 {
|
||||
stringAsCharArr = normalize(stringAsCharArr);
|
||||
char[] usedCharArr = usedChars(stringAsCharArr);
|
||||
int[] charAmountArr = countChars(usedCharArr ,stringAsCharArr);
|
||||
sort(charAmountArr,usedCharArr);
|
||||
histogramm(20,usedCharArr, charAmountArr);
|
||||
}
|
||||
|
||||
@ -36,7 +34,7 @@ public class Aufgabe2 {
|
||||
int max = maximum(charAmount);
|
||||
for(int i=0;i<availableChars.length;i++) {
|
||||
System.out.print("\""+availableChars[i]+"\": ");
|
||||
if(max>width)
|
||||
if(max>width) // scale if max width is exceeded
|
||||
for(int j=0;j<scale(charAmount[i],max,width);j++) System.out.print("#");
|
||||
else
|
||||
for(int j=0;j<charAmount[i];j++) System.out.print("#");
|
||||
@ -48,7 +46,21 @@ public class Aufgabe2 {
|
||||
double calc = (double) value/oldMax*newMax;
|
||||
return (int) calc;
|
||||
}
|
||||
|
||||
// Bubble Sort
|
||||
public static void sort(int[] amounts, char[] chars){
|
||||
for(int i=amounts.length-1;i>0; i--)
|
||||
for(int j=0;j<i;j++)
|
||||
if(amounts[j]<amounts[j+1])
|
||||
swapItems(amounts,chars,j,j+1);
|
||||
}
|
||||
public static void swapItems(int[] amounts, char[] chars, int index1, int index2){
|
||||
char memC = chars[index1];
|
||||
int memI = amounts[index1];
|
||||
chars[index1] = chars[index2];
|
||||
amounts[index1] = amounts[index2];
|
||||
chars[index2] = memC;
|
||||
amounts[index2] = memI;
|
||||
}
|
||||
public static int maximum(int[] inputArray){
|
||||
int largestNumber = inputArray[0];
|
||||
for(int i=1;i<inputArray.length;i++)
|
||||
|
Loading…
x
Reference in New Issue
Block a user