Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions BubbleSort.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
public class BubbleSort {
public BubbleSort(Integer count, Integer[] passedArray){
for(int i = 0; i < count; i++){
for(int j = 0; j < i; j++){
if(passedArray[i] <= passedArray[j]){
////Swapping using multiplication/division - buggy when any item(s) is/are 0
//passedArray[i] = passedArray[i] * passedArray[j];
//passedArray[j] = passedArray[i] / passedArray[j];
//passedArray[i] = passedArray[i] / passedArray[j];

////Swapping using XOR
//passedArray[i] = passedArray[i] ^ passedArray[j];
//passedArray[j] = passedArray[i] ^ passedArray[j];
//passedArray[i] = passedArray[i] ^ passedArray[j];

//Swapping using addition/substraction
passedArray[i] = passedArray[i] + passedArray[j];
passedArray[j] = passedArray[i] - passedArray[j];
passedArray[i] = passedArray[i] - passedArray[j];
}
}
}

for(int i = 0; i < count; i++){
System.out.println(passedArray[i]);
}
}

public static void main(String[] args){
Integer numberOfItems = args.length;
Integer[] inputsToBeSorted = new Integer[numberOfItems];

for(int i = 0; i < numberOfItems; i++){
inputsToBeSorted[i] = Integer.parseInt(args[i]);
}

try {
new BubbleSort(numberOfItems, inputsToBeSorted);
} catch (Exception e) {
System.out.println("Empty argument!");
}
}
}
37 changes: 37 additions & 0 deletions CollectionsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import java.util.*;

public class CollectionsTest {
public static void main(String[] args){
//ArrayList
List<String> names = new ArrayList<>();
names.add("ABC");
names.add("Budi");
names.add("Andy");
names.add(null);
//names.add(stringSet); //Compile error due to different object type

for(String name : names){
System.out.println(name);
}

//Set
Set<String> stringSet = new HashSet<>();
stringSet.add("String 1");
stringSet.add("String 1");
stringSet.add("String 2");
stringSet.add(null);
//stringSet.add(names); //Compile error due to different object type
for(String str : stringSet){
System.out.println(str);
}

//Map
Map<String, Integer> scoreByName = new HashMap<>();
scoreByName.put("Oliver", 100);
scoreByName.put(null, 19);
//scoreByName.put(names, 21); //Compile error due to different object type
for (Map.Entry<String, Integer> entry : scoreByName.entrySet()){ //Prints from last item
System.out.println(entry.getKey() + ": " + entry.getValue());
}
}
}
38 changes: 38 additions & 0 deletions DayPrinter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
public class DayPrinter {
public DayPrinter(Integer year, Integer month){
switch(month){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
System.out.println("31");
break;
case 4:
case 6:
case 9:
case 11:
System.out.println("30");
break;
case 2:
if(year % 4 == 0){
System.out.println("29");
} else {
System.out.println("28");
}
break;
default:
System.out.println("Invalid input!");
}
}

public static void main(String[] args){
try{
new DayPrinter(Integer.parseInt(args[0]), Integer.parseInt(args[1]));
} catch (Exception e){
System.out.println("Empty argument!");
}
}
}
19 changes: 19 additions & 0 deletions FactorialLooping.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
public class FactorialLooping {
public FactorialLooping(Integer number){
Integer result = 1;

for(int i = 1; i <= number; i++){
result = result * i;
}

System.out.println(result);
}

public static void main(String[] args){
try{
new FactorialLooping(Integer.parseInt(args[0]));
} catch(Exception e){
System.out.println("Empty argument");
}
}
}
22 changes: 22 additions & 0 deletions FactorialRecursive.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
public class FactorialRecursive {
private Integer recursive(Integer number){
if(number > 0){
return number * recursive(number - 1);
}
return 1;
}

public FactorialRecursive(Integer number){
Integer result = recursive(number);

System.out.println(result);
}

public static void main(String[] args){
try{
new FactorialRecursive(Integer.parseInt(args[0]));
} catch (Exception e){
System.out.println("Empty argument!");
}
}
}
53 changes: 53 additions & 0 deletions MonthNamePrinter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
public class MonthNamePrinter {
public MonthNamePrinter(Integer monthNumber){
switch(monthNumber){
case 1:
System.out.println("January");
break;
case 2:
System.out.println("February");
break;
case 3:
System.out.println("March");
break;
case 4:
System.out.println("April");
break;
case 5:
System.out.println("May");
break;
case 6:
System.out.println("June");
break;
case 7:
System.out.println("July");
break;
case 8:
System.out.println("August");
break;
case 9:
System.out.println("September");
break;
case 10:
System.out.println("October");
break;
case 11:
System.out.println("November");
break;
case 12:
System.out.println("December");
break;
default:
System.out.println("Input invalid!");
break;
}
}

public static void main(String[] args){
try{
new MonthNamePrinter(Integer.parseInt(args[0]));
} catch(Exception e){
System.out.println("Empty argument!");
}
}
}
29 changes: 29 additions & 0 deletions ScoreGradePrinter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
public class ScoreGradePrinter {
public ScoreGradePrinter(Integer score){
System.out.print("Your grade: ");
if(score >= 0 && score <= 20){
System.out.println("E");
System.out.println("You Have to Study Extra Extra Hard!");
} else if(score > 20 && score <= 40){
System.out.println("D");
System.out.println("You Have to Study Extra Hard!");
} else if(score > 40 && score <= 60){
System.out.println("C");
System.out.println("You Have to Study Hard!");
} else if(score > 60 && score <= 80){
System.out.println("B");
System.out.println("You Have to Study Harder!");
} else if(score > 80 && score <= 100){
System.out.println("A");
System.out.println("You Have to Maintain Your Performance!");
}
}

public static void main(String[] args){
try{
new ScoreGradePrinter(Integer.parseInt(args[0]));
} catch(Exception e){
System.out.println("Empty argument!");
}
}
}