assigment2
This commit is contained in:
parent
ae65d78044
commit
cb2460ee46
@ -1,6 +1,16 @@
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class histogram {
|
public class histogram {
|
||||||
|
|
||||||
|
private static String generateAst(int count) {
|
||||||
|
String result ="";
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
result += "*";
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void main(String args[]) {
|
public static void main(String args[]) {
|
||||||
Scanner scan = new Scanner(System.in);
|
Scanner scan = new Scanner(System.in);
|
||||||
System.out.println("Enter integers between 1 - 50");
|
System.out.println("Enter integers between 1 - 50");
|
||||||
@ -9,7 +19,6 @@ public class histogram {
|
|||||||
int int4 = 0;
|
int int4 = 0;
|
||||||
int int5 = 0;
|
int int5 = 0;
|
||||||
int int6 = 0;
|
int int6 = 0;
|
||||||
char ast = '*';
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
int int1 = scan.nextInt();
|
int int1 = scan.nextInt();
|
||||||
@ -33,10 +42,12 @@ public class histogram {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.out.println(" 1 - 10 | "+"*".repeat(int2));
|
|
||||||
System.out.println("11 - 20 | "+"*".repeat(int3));
|
|
||||||
System.out.println("21 - 30 | "+"*".repeat(int4));
|
System.out.println(" 1 - 10 | "+ (int2 > 0 ? generateAst(int2) : ""));
|
||||||
System.out.println("31 - 40 | "+"*".repeat(int5));
|
System.out.println("11 - 20 | "+ (int3 > 0 ? generateAst(int3) : ""));
|
||||||
System.out.println("41 - 50 | "+"*".repeat(int6));
|
System.out.println("21 - 30 | "+ (int4 > 0 ? generateAst(int4) : ""));
|
||||||
|
System.out.println("31 - 40 | "+ (int5 > 0 ? generateAst(int5) : ""));
|
||||||
|
System.out.println("41 - 50 | "+ (int6 > 0 ? generateAst(int6) : ""));
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -22,7 +22,19 @@ public class numbers {
|
|||||||
System.out.println("Not Positive!");
|
System.out.println("Not Positive!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Collections.sort(ints);
|
//Collections.sort(ints);
|
||||||
|
for (int i = 0; i < counter - 1; i++) {
|
||||||
|
int minValue = i;
|
||||||
|
for (int j = i + 1; j < counter; j++) {
|
||||||
|
if (ints.get(j) < ints.get(minValue)) {
|
||||||
|
minValue = j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int t = ints.get(i);
|
||||||
|
ints.set(i, ints.get(minValue));
|
||||||
|
ints.set(minValue, t);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (counter == 0) {
|
if (counter == 0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user