From 30695dfa67c7666ec9b1c7a30ec299d297ea9a1d Mon Sep 17 00:00:00 2001 From: BEAramirez29 <102708923+BEAnana29@users.noreply.github.com> Date: Thu, 23 Mar 2023 13:46:45 -1200 Subject: [PATCH 1/9] Create PrimeNumbers.java --- ProgExer1 - Prime Numbers/PrimeNumbers.java | 186 ++++++++++++++++++++ 1 file changed, 186 insertions(+) create mode 100644 ProgExer1 - Prime Numbers/PrimeNumbers.java diff --git a/ProgExer1 - Prime Numbers/PrimeNumbers.java b/ProgExer1 - Prime Numbers/PrimeNumbers.java new file mode 100644 index 0000000..3ebab1c --- /dev/null +++ b/ProgExer1 - Prime Numbers/PrimeNumbers.java @@ -0,0 +1,186 @@ +class PrimeNumbers +{ + public static void main(String[] args) + { + int count=0 ,i , j; + for(i=1; i<=100; i++) + { + for(j=i-1; j>i/2; j--) + { + if(i%j==0) + { + break; + } + } + if(j==1) + { + count++; + System.out.print(i + "\t"); + if(count%5==0) + { + System.out.println(); + } + } + } + } +} + +/* +import java.util.ArrayList; +import java.util.List; + +public class Main{ + public static void main(String[] args) + { + + int count = 0; + List prime = new ArrayList(); + prime.add(2); + + for(int i=3; i<=100; i++) + { + boolean flag = true; + for(int j=0; j1; j--) + { + if(i%j==0) + { + break; + } + } + + if(j==1) + { + count++; + System.out.print(i + "\t"); + System.out.print(count%5==0? '\n': ' '); + } + } + } +} + +*/ + + +/* created another version, with method +class PrimeNumbers +{ + public static void main(String[] args) + { + int count=0 ,i; + for(i=1; i<=100; i++) + { + if(primeOrNot(i)==true) + { + count++; + System.out.print(i + "\t"); + System.out.print(count%5==0? '\n': ' '); + } + } + } + + + public static boolean primeOrNot(int i) + { + boolean prime = false; + for(int j=i-1; j>1; j--) + { + if(i%j==0) + { + return prime; + } + } + return (i==1? prime: !prime); + } +} +*/ + +/* Last version haha (added another method lol) +class Main +{ + public static void main(String[] args) + { + int count=0 ,i; + for(i=1; i<=100; i++) + { + if(primeOrNot(i)==true) + { + count++; + primePrint(count,i); + } + } + } + + + public static boolean primeOrNot(int i) + { + boolean prime = false; + for(int j=i-1; j>1; j--) + { + if(i%j==0) + { + return prime; + } + } + return (i==1? prime: !prime); + } + + public static void primePrint(int count, int i) + { + System.out.print(i + "\t"); + System.out.print(count%5==0? '\n': ' '); + } +} +*/ \ No newline at end of file From 7a6237e326172caa616546567a830554276514a4 Mon Sep 17 00:00:00 2001 From: BEAramirez29 <102708923+BEAnana29@users.noreply.github.com> Date: Fri, 24 Mar 2023 21:05:03 -1200 Subject: [PATCH 2/9] Create Tic-Tac-Toe --- .../Tic Tac Toe/GameBoard.java | 35 ++++ ProgExer3 - Tic Tac Toe/Tic Tac Toe/Main.java | 9 + .../Tic Tac Toe/Player.java | 36 ++++ .../Tic Tac Toe/TicTacToeGame.java | 154 ++++++++++++++++++ 4 files changed, 234 insertions(+) create mode 100644 ProgExer3 - Tic Tac Toe/Tic Tac Toe/GameBoard.java create mode 100644 ProgExer3 - Tic Tac Toe/Tic Tac Toe/Main.java create mode 100644 ProgExer3 - Tic Tac Toe/Tic Tac Toe/Player.java create mode 100644 ProgExer3 - Tic Tac Toe/Tic Tac Toe/TicTacToeGame.java diff --git a/ProgExer3 - Tic Tac Toe/Tic Tac Toe/GameBoard.java b/ProgExer3 - Tic Tac Toe/Tic Tac Toe/GameBoard.java new file mode 100644 index 0000000..0bc045a --- /dev/null +++ b/ProgExer3 - Tic Tac Toe/Tic Tac Toe/GameBoard.java @@ -0,0 +1,35 @@ +public class GameBoard +{ + public String[][] positions; + public GameBoard() + { + positions = new String[][] {{"1","2","3"},{"4","5","6"},{"7","8","9"}}; + + } + + public void showBoard() + { + for(int i=0; i 8) + { + System.out.println("The game was a draw!"); + break; + } + + this.playerTurn(0); + this.boardGame.showBoard(); + int x = this.announceWinner(this.winnerChecker()); + + if(x == 1) + break; + + if(this.count > 8) + { + System.out.println("The game was a draw!"); + break; + } + + this.playerTurn(1); + this.boardGame.showBoard(); + this.announceWinner(this.winnerChecker()); + + + }while(!(this.isWinner)); + } + + public void playerTurn(int i) + { + System.out.print('\n' + this.players[i].name + ", your turn\nChoose a position in the board: "); + this.players[i].position = input.nextLine(); + + this.players[i].placePosition(this.boardGame); + this.count++; + System.out.println(); + } + + + + private void assignXorO(Player p1, Player p2) + { + + int randNumPlayer = (Math.random() * 10) > 5? 0: 1; + int randNumXorO = (Math.random() * 10) > 5? 0: 1; + + this.players[randNumPlayer].XorO = this.xO[randNumXorO]; + + int randNumPlayer2 = (randNumPlayer == 0)? 1: 0; + int randNumXorO2 = (randNumXorO == 0)? 1: 0; + + this.players[randNumPlayer2].XorO = this.xO[randNumXorO2]; + } + + public int announceWinner(String xOro) + { + if(xOro == null) + return 0; + if(this.players[0].XorO.equals(xOro)) + { + System.out.println(this.players[0].name + " wins!"); + return 1; + } + else + { + System.out.println(this.players[1].name + " wins!"); + return 1; + } + + } + + + public String winnerChecker() + { + int i=0; + if(this.boardGame.positions[i][0].equals(this.boardGame.positions[i][1]) && this.boardGame.positions[i][1].equals(this.boardGame.positions[i][2])) + { + this.isWinner = true; + return this.boardGame.positions[i][0]; + } + if(this.boardGame.positions[0][i].equals(this.boardGame.positions[1][i]) && this.boardGame.positions[1][i].equals(this.boardGame.positions[2][i])) + { + this.isWinner = true; + return this.boardGame.positions[0][i]; + } + i++; + if(this.boardGame.positions[i][0].equals(this.boardGame.positions[i][1]) && this.boardGame.positions[i][1].equals(this.boardGame.positions[i][2])) + { + this.isWinner = true; + return this.boardGame.positions[i][0]; + } + if(this.boardGame.positions[0][i].equals(this.boardGame.positions[1][i]) && this.boardGame.positions[1][i].equals(this.boardGame.positions[2][i])) + { + this.isWinner = true; + return this.boardGame.positions[0][i]; + } + i++; + if(this.boardGame.positions[i][0].equals(this.boardGame.positions[i][1]) && this.boardGame.positions[i][1].equals(this.boardGame.positions[i][2])) + { + this.isWinner = true; + return this.boardGame.positions[i][0]; + } + if(this.boardGame.positions[0][i].equals(this.boardGame.positions[1][i]) && this.boardGame.positions[1][i].equals(this.boardGame.positions[2][i])) + { + this.isWinner = true; + return this.boardGame.positions[0][i]; + } + + if(this.boardGame.positions[0][0].equals(this.boardGame.positions[1][1]) && this.boardGame.positions[1][1].equals(this.boardGame.positions[2][2])) + { + this.isWinner = true; + return this.boardGame.positions[0][0]; + } + if(this.boardGame.positions[0][2].equals(this.boardGame.positions[1][1]) && this.boardGame.positions[1][1].equals(this.boardGame.positions[2][0])) + { + this.isWinner = true; + return this.boardGame.positions[0][2]; + } + else + return null; + } + + + +} \ No newline at end of file From ce3da719a14fe5a86bfdf6a9960f273c14c028be Mon Sep 17 00:00:00 2001 From: BEAramirez29 <102708923+BEAnana29@users.noreply.github.com> Date: Fri, 24 Mar 2023 21:06:07 -1200 Subject: [PATCH 3/9] Update PrimeNumbers.java --- ProgExer1 - Prime Numbers/PrimeNumbers.java | 159 -------------------- 1 file changed, 159 deletions(-) diff --git a/ProgExer1 - Prime Numbers/PrimeNumbers.java b/ProgExer1 - Prime Numbers/PrimeNumbers.java index 3ebab1c..51d33e4 100644 --- a/ProgExer1 - Prime Numbers/PrimeNumbers.java +++ b/ProgExer1 - Prime Numbers/PrimeNumbers.java @@ -25,162 +25,3 @@ public static void main(String[] args) } } -/* -import java.util.ArrayList; -import java.util.List; - -public class Main{ - public static void main(String[] args) - { - - int count = 0; - List prime = new ArrayList(); - prime.add(2); - - for(int i=3; i<=100; i++) - { - boolean flag = true; - for(int j=0; j1; j--) - { - if(i%j==0) - { - break; - } - } - - if(j==1) - { - count++; - System.out.print(i + "\t"); - System.out.print(count%5==0? '\n': ' '); - } - } - } -} - -*/ - - -/* created another version, with method -class PrimeNumbers -{ - public static void main(String[] args) - { - int count=0 ,i; - for(i=1; i<=100; i++) - { - if(primeOrNot(i)==true) - { - count++; - System.out.print(i + "\t"); - System.out.print(count%5==0? '\n': ' '); - } - } - } - - - public static boolean primeOrNot(int i) - { - boolean prime = false; - for(int j=i-1; j>1; j--) - { - if(i%j==0) - { - return prime; - } - } - return (i==1? prime: !prime); - } -} -*/ - -/* Last version haha (added another method lol) -class Main -{ - public static void main(String[] args) - { - int count=0 ,i; - for(i=1; i<=100; i++) - { - if(primeOrNot(i)==true) - { - count++; - primePrint(count,i); - } - } - } - - - public static boolean primeOrNot(int i) - { - boolean prime = false; - for(int j=i-1; j>1; j--) - { - if(i%j==0) - { - return prime; - } - } - return (i==1? prime: !prime); - } - - public static void primePrint(int count, int i) - { - System.out.print(i + "\t"); - System.out.print(count%5==0? '\n': ' '); - } -} -*/ \ No newline at end of file From 676ba119968d7d6100032c4730434145d51da4ea Mon Sep 17 00:00:00 2001 From: BEAramirez29 <102708923+BEAnana29@users.noreply.github.com> Date: Mon, 3 Apr 2023 10:55:26 +0800 Subject: [PATCH 4/9] Created Rational class --- ProgExer6 - Rational Class/Main.java | 48 ++++++ ProgExer6 - Rational Class/Rational.java | 187 +++++++++++++++++++++++ 2 files changed, 235 insertions(+) create mode 100644 ProgExer6 - Rational Class/Main.java create mode 100644 ProgExer6 - Rational Class/Rational.java diff --git a/ProgExer6 - Rational Class/Main.java b/ProgExer6 - Rational Class/Main.java new file mode 100644 index 0000000..55deb8e --- /dev/null +++ b/ProgExer6 - Rational Class/Main.java @@ -0,0 +1,48 @@ +public class Main +{ + public static void main(String[] args) + { + Rational f1 = new Rational(2); + Rational f2 = new Rational(16,8); + + System.out.println(f1.getNumerator()); + System.out.println(f1.getDenominator()); + + System.out.println(f2.getNumerator()); + System.out.println(f2.getDenominator()); + + //returns true, since in the equal method it normalize both rational so that its simplest form is being compared + System.out.println(f1.equals(f2)); + + f2.setNumerator(-4); + f2.setDenominator(8); + + System.out.println(f1.isGreaterThan(f2)); //true + System.out.println(f1.isGreaterThanOrEqualTo(f2)); //true + System.out.println(f1.isLessThan(f2)); //false + System.out.println(f1.isLessThanOrEqualTo(f2)); //false + + //Arithmetic operations + f1.add(f2); + System.out.println(f1); //f1's value is changed to 3/2 + + f2.setNumerator(16); + f2.setDenominator(8); + + f1.subtract(f2); + System.out.println(f1); // -1/2 + + f1.multiply(f2); + System.out.println(f1); // -1/1 + + f1.divide(f2); + System.out.println(f1); // -1/2 + + f2.setNumerator(16); + f2.setDenominator(8); + + f2.normalize(); + System.out.println(f2); // 2/1 + + } +} \ No newline at end of file diff --git a/ProgExer6 - Rational Class/Rational.java b/ProgExer6 - Rational Class/Rational.java new file mode 100644 index 0000000..b96b394 --- /dev/null +++ b/ProgExer6 - Rational Class/Rational.java @@ -0,0 +1,187 @@ +public class Rational +{ + private int numerator; + private int denominator; + + public Rational(int numerator, int denominator) + { + this.numerator = numerator; + if(denominator != 0) + this.denominator = denominator; + else + this.denominator = 1; + } + + public Rational(int wholeNumber) + { + this.numerator = wholeNumber; + this.denominator = 1; + } + + public Rational() + { + this.numerator = 0; + this.denominator = 1; + } + + public int getNumerator() + { + return this.numerator; + } + + public int getDenominator() + { + return this.denominator; + } + + public void setNumerator(int numerator) + { + this.numerator = numerator; + } + + public void setDenominator(int denominator) + { + if(denominator != 0) + this.denominator = denominator; + else + this.denominator = 1; + } + + public boolean isLessThan(Rational fraction) + { + if((this.numerator*fraction.getDenominator()) < (fraction.getNumerator()*this.denominator)) + return true; + else + return false; + } + + public boolean isLessThanOrEqualTo(Rational fraction) + { + if((this.numerator*fraction.getDenominator()) <= (fraction.getNumerator()*this.denominator)) + return true; + else + return false; + } + + public boolean isGreaterThan(Rational fraction) + { + if((this.numerator*fraction.getDenominator()) > (fraction.getNumerator()*this.denominator)) + return true; + else + return false; + } + + public boolean isGreaterThanOrEqualTo(Rational fraction) + { + if((this.numerator*fraction.getDenominator()) >= (fraction.getNumerator()*this.denominator)) + return true; + else + return false; + } + + public void add(Rational fraction) + { + int addDenominator = this.denominator * fraction.getDenominator(); + int addNumerator = (((addDenominator/this.denominator)*this.numerator)+(((addDenominator/fraction.getDenominator())*fraction.getNumerator()))); + this.denominator = addDenominator; + this.numerator = addNumerator; + this.normalize(); + + } + + public void subtract(Rational fraction) + { + int subDenominator = this.denominator * fraction.getDenominator(); + int subNumerator = (((subDenominator/this.denominator)*this.numerator)-(((subDenominator/fraction.getDenominator())*fraction.getNumerator()))); + this.denominator = subDenominator; + this.numerator = subNumerator; + this.normalize(); + } + + public void multiply(Rational fraction) + { + int multDenominator = this.denominator * fraction.getDenominator(); + int multNumerator = this.numerator * fraction.getNumerator(); + this.denominator = multDenominator; + this.numerator = multNumerator; + this.normalize(); + } + + public void divide(Rational fraction) + { + int divDenominator = this.denominator * fraction.getNumerator(); + int divNumerator = this.numerator * fraction.getDenominator(); + this.denominator = divDenominator; + this.numerator = divNumerator; + this.normalize(); + } + + public void normalize() + { + boolean isNumNegative = false, isDenomNegative = false; + + if(this.numerator < 0) + { + this.numerator *= -1; + isNumNegative = true; + } + + if(this.denominator < 0) + { + this.denominator *= -1; + isDenomNegative = true; + } + + int smallNum = (this.numerator Date: Mon, 3 Apr 2023 11:05:54 +0800 Subject: [PATCH 5/9] Create QuartersDimesPennies.java --- .../QuartersDimesPennies.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 ProgExer2 - Quarters, Dimes, and Pennies/QuartersDimesPennies.java diff --git a/ProgExer2 - Quarters, Dimes, and Pennies/QuartersDimesPennies.java b/ProgExer2 - Quarters, Dimes, and Pennies/QuartersDimesPennies.java new file mode 100644 index 0000000..36c2a43 --- /dev/null +++ b/ProgExer2 - Quarters, Dimes, and Pennies/QuartersDimesPennies.java @@ -0,0 +1,52 @@ +import java.util.*; +public class QuartersDimesPennies +{ + public static void main(String[] args) + { + Scanner input = new Scanner(System.in); + int[] coinValue = {25, 10, 1}; + int[] coinDenomination = new int[3]; + int[] arrchange = new int[2]; + int amountOfChange; + String yesOrNo = "y"; + + do + { + System.out.print("\nEnter the amount of change (from 1-99): "); + amountOfChange = input.nextInt(); + if(amountOfChange > 100 || amountOfChange < 1) + { + System.out.println("Error: Invalid amount, range is from 1 to 99."); + continue; + } + int temp = amountOfChange; + for(int i = 0; i < coinValue.length; i++) + { + arrchange = computeCoin(coinValue[i],amountOfChange); + amountOfChange = arrchange[1]; + coinDenomination[i] = arrchange[0]; + } + System.out.println(temp + " cents can be given as"); + System.out.printf("%d quarter(s) %d dime(s) %d penny(pennies)\n\n",coinDenomination[0],coinDenomination[1], coinDenomination[2]); + System.out.print("Do you want to enter another amount? [y|n]"); + input.nextLine(); + yesOrNo = input.nextLine(); + + }while(yesOrNo.equalsIgnoreCase("y")); + } + + public static int[] computeCoin(int coinValue, int amountLeft) + { + int[] arr = new int[2]; + int number = amountLeft; + if((coinValue > 0 && coinValue < 100) && (amountLeft >= 0 && amountLeft < 100)) + { + number /= coinValue; + amountLeft %= coinValue; + arr[0] = number; + arr[1] = amountLeft; + return arr; + } + return arr; + } +} From 9bf1b4fc4efc43a4869f560fb14eb1554e38987c Mon Sep 17 00:00:00 2001 From: BEAramirez29 <102708923+BEAnana29@users.noreply.github.com> Date: Thu, 6 Apr 2023 13:48:37 +0800 Subject: [PATCH 6/9] Create Airline.java --- ProgExer4 - Airline Seats/Airline.java | 78 ++++++++++++++++++++++ ProgExer4 - Airline Seats/AirlineTest.java | 25 +++++++ 2 files changed, 103 insertions(+) create mode 100644 ProgExer4 - Airline Seats/Airline.java create mode 100644 ProgExer4 - Airline Seats/AirlineTest.java diff --git a/ProgExer4 - Airline Seats/Airline.java b/ProgExer4 - Airline Seats/Airline.java new file mode 100644 index 0000000..68625e9 --- /dev/null +++ b/ProgExer4 - Airline Seats/Airline.java @@ -0,0 +1,78 @@ +import java.util.*; +public class Airline +{ + + int[][] airlineSeats; + public Airline(int[][] airlineSeats) + { + this.airlineSeats = airlineSeats; + } + + public void displayAirlineSeats() + { + System.out.println(); + for(int i=0; i 7 || seatNumber < 1) || (Character.toUpperCase(seatChar) < 'A' || Character.toUpperCase(seatChar) > 'F')) + { + System.out.println("Error: Invalid input. (Range is 1A - 7D)."); + this.displayAirlineSeats(); + this.inputSeat(); + } + else if(this.isSeatAvailable(seatNumber, seatChar)) + this.airlineSeats[seatNumber-1][letterToArrayNum(seatChar)] = 'X'; + else + { + System.out.println("Error: Invalid seat location, it's occupied."); + this.displayAirlineSeats(); + this.inputSeat(); + } + } + + public int letterToArrayNum(char seatChar) + { + switch(seatChar) + { + case 'A': + return 0; + case 'B': + return 1; + case 'C': + return 2; + case 'D': + return 3; + } + return -1; + } + + public void inputSeat() + { + System.out.print("\nPlease choose an unoccupied seat location (from 1A to 7D): "); + Scanner scanner = new Scanner(System.in); + String seatLocation; + + seatLocation = scanner.next(); + + pickSeat(Character.getNumericValue(seatLocation.charAt(0)), Character.toUpperCase(seatLocation.charAt(1))); + } +} + diff --git a/ProgExer4 - Airline Seats/AirlineTest.java b/ProgExer4 - Airline Seats/AirlineTest.java new file mode 100644 index 0000000..d85098e --- /dev/null +++ b/ProgExer4 - Airline Seats/AirlineTest.java @@ -0,0 +1,25 @@ +import java.util.*; +public class AirlineTest +{ + public static void main(String[] args) + { + int[][] airlineSeats = {{'A','B','C','D'},{'A','B','C','D'},{'A','B','C','D'},{'A','B','C','D'},{'A','B','C','D'},{'A','B','C','D'},{'A','B','C','D'}}; + Scanner input = new Scanner(System.in); + String yOrN, yes = "y"; + + Airline airline = new Airline(airlineSeats); + + do + { + airline.displayAirlineSeats(); + airline.inputSeat(); + airline.displayAirlineSeats(); + + + System.out.print("Get another seat? [y|n] "); + yOrN = input.next(); + + }while(yes.equals(yOrN.toLowerCase())); + + } +} \ No newline at end of file From e6692516c1d29f4484f8d850305a96fbcb430636 Mon Sep 17 00:00:00 2001 From: BEAramirez29 <102708923+BEAnana29@users.noreply.github.com> Date: Thu, 6 Apr 2023 13:54:15 +0800 Subject: [PATCH 7/9] Update Airline.java --- ProgExer4 - Airline Seats/Airline.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ProgExer4 - Airline Seats/Airline.java b/ProgExer4 - Airline Seats/Airline.java index 68625e9..c8c994e 100644 --- a/ProgExer4 - Airline Seats/Airline.java +++ b/ProgExer4 - Airline Seats/Airline.java @@ -32,7 +32,7 @@ public boolean isSeatAvailable(int seatNumber, char seatChar) public void pickSeat(int seatNumber, char seatChar) { - if((seatNumber > 7 || seatNumber < 1) || (Character.toUpperCase(seatChar) < 'A' || Character.toUpperCase(seatChar) > 'F')) + if((seatNumber > 7 || seatNumber < 1) || (Character.toUpperCase(seatChar) < 'A' || Character.toUpperCase(seatChar) > 'D')) { System.out.println("Error: Invalid input. (Range is 1A - 7D)."); this.displayAirlineSeats(); From 8b36242efcac91a5ad7e751d30d9bb72ce101a04 Mon Sep 17 00:00:00 2001 From: BEAramirez29 <102708923+BEAnana29@users.noreply.github.com> Date: Thu, 6 Apr 2023 19:31:17 +0800 Subject: [PATCH 8/9] Create NumberCounter.java --- ProgExer5 - Number Counter/NumberCounter.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 ProgExer5 - Number Counter/NumberCounter.java diff --git a/ProgExer5 - Number Counter/NumberCounter.java b/ProgExer5 - Number Counter/NumberCounter.java new file mode 100644 index 0000000..6ea04b7 --- /dev/null +++ b/ProgExer5 - Number Counter/NumberCounter.java @@ -0,0 +1,53 @@ +import java.util.*; +public class NumberCounter +{ + public static void main(String[] args) + { + int[] inputNumbers = new int[16]; + List uniqueNumbers = new ArrayList(); + + Scanner input = new Scanner(System.in); + + int count = 0; + + System.out.println("Enter 16 numbers [duplicates allowed]."); + while(count < 16) + { + inputNumbers[count] = input.nextInt(); + count++; + } + + uniqueNumbers.add(inputNumbers[0]); + + //finding unique elements in inputNumbers and storing it to the uniqueNumbers List + for(int i=1; i<16; i++) + { + if(uniqueNumbers.get(0) != inputNumbers[i]) + { + for(int j=0; j Date: Sat, 8 Apr 2023 13:49:47 +0800 Subject: [PATCH 9/9] Create DeleteRepeats.java --- ProgExer7 - Delete Repeats/DeleteRepeats.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 ProgExer7 - Delete Repeats/DeleteRepeats.java diff --git a/ProgExer7 - Delete Repeats/DeleteRepeats.java b/ProgExer7 - Delete Repeats/DeleteRepeats.java new file mode 100644 index 0000000..4acbbe4 --- /dev/null +++ b/ProgExer7 - Delete Repeats/DeleteRepeats.java @@ -0,0 +1,48 @@ +import java.util.*; +public class DeleteRepeats +{ + + public static void main(String[] args) + { + Scanner input = new Scanner(System.in); + + System.out.print("\nEnter an array of characters (30 max): "); + String word = input.next(); + System.out.println("\nstring: " + word + "\nsize: " + word.length()); + System.out.println("\nAfter deleting the repeating characters...\n"); + System.out.println("string: " + deleteRepeats(word) +"\nsize: " + deleteRepeats(word).length()); + + } + + + public static String deleteRepeats(String originalString) + { + char[] arrChar = new char[30]; + arrChar[0] = originalString.charAt(0); + int count = 1; + + for(int i=1; i