I need to make a recursive method that converts a decimal into hexadecimal.
I can't use Integer.toHexString.
EDIT:I tried this code but it doesn't work properly
public static String Hexa(String s) {
String result = "";
int n = Integer.parseInt(s);
int remainder = n % 16;
if (n == 0) {
return Integer.toString(0);
} else {
switch (remainder) {
case 10:
result = "A" + result;
break;
case 11:
result = "B" + result;
break;
case 12:
result = "C" + result;
break;
case 13:
result = "D" + result;
break;
case 14:
result = "E" + result;
break;
case 15:
result = "F" + result;
break;
default: result = Integer.toString(n/16) + result; break;
}
System.out.println(result);
return Hexa(Integer.toString(n/16)) + result;
}
}
Edit:
Changed the default case and the if (n == 0) loop return statement and it works beautifully now.
new code:
public static String Hexa(String s) {
String result = "";
int n = Integer.parseInt(s);
int remainder = n % 16;
if (n == 0) {
return "";
} else {
switch (remainder) {
case 10:
result = "A";
break;
case 11:
result = "B";
break;
case 12:
result = "C";
break;
case 13:
result = "D";
break;
case 14:
result = "E";
break;
case 15:
result = "F";
break;
default:
result = remainder + result;
break;
}
return Hexa(Integer.toString(n / 16)) + result;
}
}
The problem is in your default clause:
default: result = Integer.toString(n/16) + result; break;
it should read:
default: result = Integer.toString(remainder) + result; break;
That will make your program return "04D2".
But there are several other corrections you can make:
Stop converting back and forth to String. For example that same line can be just:
default: result = remainder + result; break;
Also, change your parameters time to int. If you do need to receive a String, then make this an auxiliary function and make your main function receive a String.
You don't need that breakat the end of your default
You don't need a switch. Isn't 'F' = 'A' + (15 - 10) ? You can figure out how to make a formula that translates any number in the range [10,15] to its corresponding letter.
Instead of Integer.toString(0) you can use "0" ... but that isn't even necessary, you can use "" to avoid that leading 0 in your output. If your are worried for handling the special case where the whole number is "0" add a special clause.
The code below may help you to solve your problem:
public static String decimalToAnyBase(int num,int base) {
if(num<base) {
return num+"";
}
String result=null;
int rem=num%base;
String str=decimalToAnyBase(num/base, base);
result=str+((rem>=10)? (char)(rem-10+'A')+"":rem);
return result;
}
import java.util.Scanner;
public class Assign01_05
{
static String res;
public static void hex(int num) //125
{
if(num>=0 && num<10)
System.out.print(num);
else if(num>=10 && num<=15)
{
switch(num)
{
case 10:
System.out.print('A');
break;
case 11:
System.out.print('B');
break;
case 12:
System.out.print('C');
break;
case 13:
System.out.print('D');
break;
case 14:
System.out.print('E');
break;
case 15:
System.out.println('F');
break;
}
}
else
{
hex(num/16);
hex(num%16);
}
}
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Demical number :");
int num=sc.nextInt();
hex(num);
}
}
import java.util.Scanner;
public class Assign01_05
{
static String res;
public static void hex(int num) //125
{
if(num>=0 && num<10)
System.out.print(num);
else if(num>=10 && num<=15)
{
switch(num)
{
case 10:
System.out.print('A');
break;
case 11:
System.out.print('B');
break;
case 12:
System.out.print('C');
break;
case 13:
System.out.print('D');
break;
case 14:
System.out.print('E');
break;
case 15:
System.out.println('F');
break;
}
}
else
{
hex(num/16);
hex(num%16);
}
}
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Demical number :");
int num=sc.nextInt();
hex(num);
}
}
import java.util.Scanner;
public class Ques5 {
public static void hex(int n) {
if(n>9&&n<=15) {
System.out.printf("%c",'A'+(n-10));
}
else if(n>=0&&n<=9){
System.out.printf("%d",n);
}
else {
hex(n/16);
hex(n%16);
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the decimal number : ");
int i = sc.nextInt();
System.out.println("The hexadecimal number is : ");
hex(i);
sc.close();
}
}
const char hex_string[17] = "0123456789ABCDEF";
void dec_to_hex(long long x){
if(x == 0) return;
dec_to_hex(x/16);
printf("%c",hex_string[x%16]);
}
Same in Java
Related
The program ask for a month and it could be a string or int. In the isDigitsOrSpecial method, it works and it has the same format in my method isString. The difference is that when I want to enter the month in a string way (ex.january), it will ask me twice. So, I don't know what to do. I tried a lot of ways but it doesn't work. Do you have any suggestions?
Here's my full code. You can try to run it, and see the problem where you have to input twice the name of the month in a string way.
I would really appreciate any of your suggestions.
package Electronic_payment_process;
import java.util.InputMismatchException;
import java.util.Scanner;
public class practice {
static String s;
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
float current = 0, recent = 0, difference, multiply;
String month, recents, currents = null;
System.out.println("The month could be a number or a name.");
System.out.println("Example: (01-12) or (JAN – dec)");
// for the validation of due month user’s input
do {
System.out.print("\nEnter a month: ");
month = scan.next();
if (isDigitsOrSpecial(month)) {
System.out.print("proceed");
break;
} else if (isString(month)) {
System.out.print("proceed");
break;
}
} while (true);
// for the validation of current meter reading
do {
System.out.print("\nEnter current reading: ");
try {
current = scan.nextFloat();
System.out.println("proceed");
currents = String.format("%.2f", current);
if (current <= 0) {
System.out.println("Invalid input");
}
} catch (InputMismatchException a) {
System.out.println("Must enter a number");
scan.next();
}
} while (current <= 0);
// for the validation of recent meter reading
do {
System.out.print("Enter recent reading: ");
try {
recent = scan.nextFloat();
if (recent < current) {
System.out.println("proceed");
recents = String.format("%.2f", recent);
break;
} else {
System.out.println("recent must be less than current");
}
} catch (InputMismatchException a) {
System.out.println("Must enter a number");
scan.next();
}
} while (true);
difference = current - recent;
multiply = difference * 50;
System.out.println("====================================================================================");
System.out.println("MONTH " + " RECENT " + "CURRENT " + "TOTAL USAGE " + "Price per unit " + "TOTAL AMOUNT ");
System.out.println((s + (" ") + recents + (" kW") + (" ") + currents + (" kW") + (" ") + difference + (" ") + ("50php") + (" ") + multiply));
}
public static boolean isDigitsOrSpecial(String month) {
Scanner scan = new Scanner(System.in);
if (month != null) {
for (char ch : month.toCharArray()) {
if (Character.isLetter(ch)) {
return false;
}
}
}
int we = Integer.parseInt(month);
s = Integer.toString(we);
if (null == month) {
s = scan.nextLine();
} else switch (we) {
case 01:
s = "January";
break;
case 02:
s = "February";
break;
case 03:
s = "March";
break;
case 04:
s = "April";
break;
case 05:
s = "May";
break;
case 06:
s = "June";
break;
case 07:
s = "July";
break;
case 8:
s = "August";
break;
case 9:
s = "September";
break;
case 10:
s = "October";
break;
case 11:
s = "November";
break;
case 12:
s = "December";
break;
default:
System.out.println("You have entered an invalid number of month");
}
return true;
}
public static boolean isString(String month) {
Scanner scan = new Scanner(System.in);
if (null != month) {
char[] chars = month.toCharArray();
s = scan.nextLine();
for (char c : chars) {
if (!Character.isLetter(c)) {
return false;
}
}
}
if (!(month.length() >= 3)) {
System.out.println("Name of month must be at least 3 letters.Please try again");
return false;
} else if (month.startsWith("jan") || month.startsWith("JAN") || month.startsWith("Jan")) {
s = "January";
}
return true;
}
}
I see we have added additional scanner statements inside isDigit or isString methods. I have removed them and it looks good to me.
public static boolean isDigitsOrSpecial(String month) {
if (month != null) {
for (char ch : month.toCharArray()) {
if (Character.isLetter(ch)) {
return false;
}
}
}
int we = Integer.parseInt(month);
switch (we) {
case 01:
s = "January";
break;
case 02:
s = "February";
break;
case 03:
s = "March";
break;
case 04:
s = "April";
break;
case 05:
s = "May";
break;
case 06:
s = "June";
break;
case 07:
s = "July";
break;
case 8:
s = "August";
break;
case 9:
s = "September";
break;
case 10:
s = "October";
break;
case 11:
s = "November";
break;
case 12:
s = "December";
break;
default:
System.out.println("You have entered an invalid number of month");
return false;
}
return true;
}
public static boolean isString(String month)
{
if (null != month) {
char[] chars = month.toCharArray();
for (char c : chars) {
if (!Character.isLetter(c)) {
return false;
}
}
}
if (!(month.length() >= 3)) {
System.out.println("Name of month must be at least 3 letters.Please try again");
return false;
}
return true;
}
The assignment for the project that I am working on is for the user to be able to input a zip code and for the program to provide the bar code in the output. For example, the bar code for 95014 right now should be "|:|:::|:|:||::::::||:|::|". This is all based on a table I have that denotes what each number should be (shown in the case statements). This is the code I wrote for that portion:
public class Zipcode{
private String zipcode = "";
private String barcode = "";
private int zipnum = 0;
public Zipcode(int zip_number){
zipnum = zip_number;
}
public void createBarcode(){
while (zipnum > 0){
switch (zipnum % 10)
{
case 0:
barcode = "||:::";
break;
case 1:
barcode = ":::||";
break;
case 2:
barcode = "::|:|";
break;
case 3:
barcode = "::||:";
break;
case 4:
barcode = ":|::|";
break;
case 5:
barcode = ":|:|:";
break;
case 6:
barcode = ":||::";
break;
case 7:
barcode = "|:::|";
break;
case 8:
barcode = "|::|:";
break;
case 9:
barcode = "|:|::";
break;
default:
break;
}
barcode += barcode;
zipnum = zipnum / 10;
}
}
public String getBarcode(){
return barcode;
}
}
However, when my tester class calls this class after the user inputs a zip code, nothing comes up as the result. Please help! Why isn't anything being returned? I don't know what I am doing wrong.
Notice that you re-assign barcode variable in each switch-case block and append itself again in the end.
You can do it with a temporary variable inside the method:
public void createBarcode(){
String tempBarcode = "";
...
case 0:
tempBarcode = "||:::";
break;
....
barcode += tempBarcode;
But I think the cleanest solution would be to use it as an utility method without any class variable dependencies:
public static String calculateBarcode(int zipNumber) {
StringBuilder barcode = new StringBuilder();
while (zipNumber > 0) {
switch (zipNumber % 10) {
case 0:
barcode.append("||:::");
break;
case 1:
barcode.append(":::||");
break;
...
...
default:
break;
}
zipNumber = zipNumber / 10;
}
return barcode.toString();
}
Simple testcase:
public static void main(String[] args) {
System.out.println(ZipcodeUtil.calculateBarcode(95014));
/* Output: :|::|:::||||::::|:|:|:|:: */
}
You aren't appending the zip value on every iteration correctly. The value is getting lost as you are overriding the value here on this step
...
case 0:
barcode = "||:::";
break;
...
Instead use a temporary variable to store the current iterations zip code value
public class Zipcode {
private String zipcode = "";
private String barcode = "";
private int zipnum = 0;
public Zipcode(int zip_number) {
zipnum = zip_number;
}
public void createBarcode() {
String temp_barcode = "";
while (zipnum > 0) {
System.out.println(zipnum % 10);
switch (zipnum % 10) {
case 0:
temp_barcode = "||:::";
System.out.println(0);
break;
case 1:
temp_barcode = ":::||";
System.out.println(1);
break;
case 2:
temp_barcode = "::|:|";
System.out.println(2);
break;
case 3:
temp_barcode = "::||:";
System.out.println(3);
break;
case 4:
temp_barcode = ":|::|";
System.out.println(4);
break;
case 5:
temp_barcode = ":|:|:";
System.out.println(5);
break;
case 6:
temp_barcode = ":||::";
System.out.println(6);
break;
case 7:
temp_barcode = "|:::|";
System.out.println(7);
break;
case 8:
temp_barcode = "|::|:";
System.out.println(8);
break;
case 9:
temp_barcode = "|:|::";
System.out.println(9);
break;
default:
break;
}
barcode += temp_barcode;
System.out.println(barcode);
zipnum = zipnum / 10;
}
}
public String getBarcode() {
return barcode;
}
public static void main(String args[]) {
Zipcode z = new Zipcode(95014);
z.createBarcode();
System.out.println(z.getBarcode()); // output: :|::|:::||||::::|:|:|:|::
}
}
Add barcode this way
case 0:
barcode += "||:::";
break;
case 1:
barcode += ":::||";
break;
case 2:
barcode += "::|:|";
break;
case 3:
.....
.....
.....
and remove this line
barcode += barcode;
This will solve your issue.
Your barcode variable overwrite in your code so add local variable in createBarcode method. try this:
public class Zipcode{
private String zipcode = "";
private String barcode = "";
private int zipnum = 0;
public static void main(String[] a){
Zipcode z = new Zipcode(1568);
System.out.println(z.zipnum);
z.createBarcode();
System.out.println(z.zipnum);
System.out.println(z.getBarcode());
}
public Zipcode(int zip_number){
zipnum = zip_number;
}
public void createBarcode(){
while (zipnum > 0){
String barcode;
switch (zipnum % 10)
{
case 0:
barcode = "||:::";
break;
case 1:
barcode = ":::||";
break;
case 2:
barcode = "::|:|";
break;
case 3:
barcode = "::||:";
break;
case 4:
barcode = ":|::|";
break;
case 5:
barcode = ":|:|:";
break;
case 6:
barcode = ":||::";
break;
case 7:
barcode = "|:::|";
break;
case 8:
barcode = "|::|:";
break;
case 9:
barcode = "|:|::";
break;
default:
barcode = "";
break;
}
this.barcode += barcode;
zipnum = zipnum / 10;
}
}
public String getBarcode(){
return barcode;
}
}
First create a Zipcode instance, Zipcode code = Zipcode(9)
Then call createBarcode() for that instance, so in my case code.createBarcode()
Then you can print out the getBarcode() method.
REMEMBER, getBarcode() only returns a String with the barcode but it does not print it out. You must use print to print it out.
EXAMPLE: System.out.println(code.getBarcode())
Hopefully you can see what I am going for here. Obviously this code doesn't work but I'm basically trying to say if the random number is one of these values, run this code. If the random number is another value run that code. I need something that is equivalent to a big or statement without using a large if-else. Thanks
static int cardNumber = rnd.nextInt(13) + 1;
if (cardNumber == 1||11||12||13)
{
System.out.println(faceCard + " of " + suit);
}
else
{
System.out.println(cardNumber + " of " + suit);
}
You could benefit from a switch / case :
switch (caseNumber) {
case 1 : case 11 : case 12 : case 13 :
<specific case code>;
break;
default :
<general case code>;
break;
}
Well, it's not a large if/else, it's just two conditions:
static int cardNumber = rnd.nextInt(13) + 1;
if (cardNumber == 1 || cardNumber >= 11)
{
System.out.println(faceCard + " of " + suit);
}
else
{
System.out.println(cardNumber + " of " + suit);
}
Use a switch(int) to clarify
static int cardNumber = rnd.nextInt(13) + 1;
switch (cardNumber)
case 1:
case 11:
case 12:
case 13:
System.out.println(faceCard + " of " + suit);
break;
default:
System.out.println(cardNumber + " of " + suit);
break;
}
You could just simplify it I suppose, in your case specifically this might work..
int cn = rnd.nextInt(13) + 1;
if(cn <= 10 && cn > 1) {
System.out.println("Non-Face");
} else {
System.out.println("Face");
}
You could use a switch case with a fallthrough.
public static void main(String args[]) {
int cardNumber = 10;
switch (cardNumber) {
case 1:
case 11:
case 12:
case 13:
// your if case
break;
case 100:
// some other case (example)
break;
default:
// else case
break;
}
}
You could also write a method which tells you if a card has a face!
This would be a lot easier to use and would prevent redundant code.
Also you could the class card, instead of an integer to save your card value.
An Enum wouldn't be bad either.
class Card {
public static boolean hasFace(int cardNum) {
if (cardNum > 13)
throw new InvalidParameterException("There is no card with a value greater 31!");
boolean rval = false;
switch (cardNum) {
case 1:
case 11:
case 12:
case 13:
rval = true;
break;
default:
break;
}
return rval;
}
}
Main for case 2:
public static void main(String args[]) {
int cardNumber = 10;
if(Card.hasFace(cardNumber)){
// your if case
}
else {
// your else case
}
}
this code is supposed to recieve two integers and an operation and then calculate the numbers. this is only part of the entire program everything else works but the calculations are wrong. The only correct output that i get when i run the whole thing is the subtraction. Whats wrong with it?
public static double calculate(int operand1, int operand2, char operation)
{
if (operation=='^')
{
return (Math.pow(operand1,operand2));
}
else if(operation=='+')
{
return ((operand1)+(operand2));
}
else if(operation=='-')
{
return (operand1-operand2);
}
else if(operation=='*')
{
return (operand1*operand2);
}
else
{
if (operand2==0)
{
System.out.println("Cant divide by zero");
}
return(operand1/operand2);
}
}
Here is the entire code for the program
import java.util.Scanner;
public class Calculator
{
public static void main(String[] args)
{
printIntro();
Scanner kb = new Scanner(System.in);
String answer = "yes";
while (answer.equals("yes"))
{
System.out.println("Enter your problem");
String fullExpression=kb.nextLine();
fullExpression=fullExpression.replaceAll("\\s","");
int length=fullExpression.length();
char op1=fullExpression.charAt(0);
char op2=fullExpression.charAt(1);
String operation=fullExpression.substring(2,length);
printEnglish(op1,op2,operation);
System.out.println("Type yes to continue");
Scanner kb1 = new Scanner(System.in);
answer=kb1.nextLine();
};
}
/*this methods gets the operands and the operation and
prints the English version: if we call this method
printEnglish(2,3, plus), then this method will output:
Two plus three = 5 */
public static void printEnglish(char op1, char op2, String operation)
{
String resultOp1CharToString=charToString(op1);
String resultOp2CharToString=charToString(op2);
char resultOperationConversion=operationConversion(operation);
double resultCalculate=calculate(op1, op2, resultOperationConversion);
System.out.print(resultOp1CharToString+ operationConversion(operation) + resultOp2CharToString+ "=" + resultCalculate);
/*1. call the method charToString(op1) to convertlish
word for example ‘1’ to one or ‘2’ to two,….
2. call the method operandConversionToNumber(op1) to
get its numeric value. For example if op1 is ‘1’ then
this method call should return the integer value 1
3. call the method operationConversion(operation) to
convert the operation to a mathematical operation. For
example if you call this method with the string plus
then it will return ‘+’
4. finally call the method calculate to get the result
of the operation.*/
}
/*this method prints the numeric version which is 2 *3
=6*/
//public static boolean printNumeric(char op1, char op2, String operation)
//{
/*String resultCharToString=charToString(op1);
String resultCharToString2=charToString(op2);
int resultOperandToNumber=operandConversionToNumber(op1);
int resultOperandToNumber2=operandConversionToNumber(op2);
char resultOperationConversion=operationConversion(operation);
double resultCalculate=calculate(op1, op2, operation); */
//}
/*this method gets a number as a character and returns
its numeric value as an integer. You must use case
statement for this method*/
public static int operandConversiontoNumber(char operand)
{
int numberOperand=0;
switch(operand)
{
case '0':
numberOperand=0;
break;
case '1':
numberOperand=1;
break;
case '2':
numberOperand=2;
break;
case '3':
numberOperand=3;
break;
case '4':
numberOperand=4;
break;
case '5':
numberOperand=5;
break;
case '6':
numberOperand=6;
break;
case '7':
numberOperand=7;
break;
case '8':
numberOperand=8;
break;
case '9':
numberOperand=9;
break;
}
return numberOperand;
}
/*this method gets the operation as a string and
return the equivalent operation in math. For example
if it receives “plus” the it will return ‘+’ */
public static char operationConversion(String s)
{
char operation=0;
if(s.equals("plus"))
{
operation= '+';
}
else if(s.equals("minus"))
{
operation= '-';
}
else if(s.equals("multiply"))
{
operation= '*';
}
else if(s.equals("divide"))
{
operation= '/';
}
else
{
operation= '^';
}
return operation;
}
/*this method recives two numbers and the operation
and returns the result*/
public static double calculate(int operand1, int operand2, char operation)
{
if (operation=='^')
{
return (Math.pow(operand1,operand2));
}
else if(operation=='+')
{
return ((operand1)+(operand2));
}
else if(operation=='-')
{
return (operand1-operand2);
}
else if(operation=='*')
{
return (operand1*operand2);
}
else
{
if (operand2==0)
{
System.out.println("Cant divide by zero");
}
return(operand1/operand2);
}
}
/*this method converst a number character to its
English word for example if this method receives ‘1’
it will return “one” */
public static String charToString(char num)
{
String englishOperand="one";
switch(num)
{
case '0':
englishOperand= "zero";
break;
case '1':
englishOperand="one";
break;
case '2':
englishOperand="two";
break;
case '3':
englishOperand="three";
break;
case '4':
englishOperand= "four";
break;
case '5':
englishOperand= "five";
break;
case '6':
englishOperand= "six";
break;
case '7':
englishOperand= "seven";
break;
case '8':
englishOperand= "eight";
break;
case '9':
englishOperand= "nine";
break;
}
return englishOperand;
}
//this method prints the decription of this program.
public static void printIntro()
{
System.out.println("This program is a calculator, you need to enter two");
System.out.println("single digit numbers and an operation(plus, minus,");
System.out.println("divide, multiply, power) and it outputs its numeric");
System.out.println("and English version. Your operand and operation can be");
System.out.println("separated by space(s) or there could be no spaces");
System.out.println("between them. For example you can enter “23plus” or “2 3 plus”");
}
}
I entered 2 3 plus and i expect 5 but i dont recieve that, but when i enter 2 3 minus i recieve -1
if (operand2==0)
{
System.out.println("Cant divide by zero");
return -1; // some dummy value
}
else
{
return(operand1/operand2);
}
Division will be incorrect as it's doing integer division and you want a double result. It will also throw a divide by zero error because you don't return.
if (operand2 == 0)
{
System.out.println("Cant divide by zero");
return 0; // I guess
}
return (double)operand1 / (double)operand2;
All the rest look like they should work fine.
I am using ISO9075 decoder in my application. When I try to decode the following String
ISO9075.decode("mediaasset_-g9mdob83oozsr5n_xadda")
its giving the following exception
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 22
at java.lang.String.charAt(Unknown Source)
at org.alfresco.util.ISO9075.matchesEncodedPattern(ISO9075.java:128)
at org.alfresco.util.ISO9075.decode(ISO9075.java:176)
at Test1.main(Test1.java:9)
What may be the problem. Please guide me.
EDIT
Here is my code
public class Test1 {
public static void main(String args[])
{
String s = "mediaasset_-g9mdob83oozsr5n_xadda";
System.out.println(ISO9075.decode(s));
}
}
Thanks.
I just tested it with code found here and could not get your exception.
public static void main(String args[]) {
String s = "mediaasset_-g9mdob83oozsr5n_xadda";
System.out.println(ISO9075.decode(s)); //prints mediaasset_-g9mdob83oozsr5n_xadda
}
public static class ISO9075 {
//I have removed the parts not used by your main()
private static boolean matchesEncodedPattern(String string, int position) {
return (string.length() > position + 6)
&& (string.charAt(position) == '_') && (string.charAt(position + 1) == 'x')
&& isHexChar(string.charAt(position + 2)) && isHexChar(string.charAt(position + 3))
&& isHexChar(string.charAt(position + 4)) && isHexChar(string.charAt(position + 5))
&& (string.charAt(position + 6) == '_');
}
private static boolean isHexChar(char c) {
switch (c) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
return true;
default:
return false;
}
}
public static String decode(String toDecode) {
if ((toDecode == null) || (toDecode.length() < 7) || (toDecode.indexOf("_x") < 0)) {
return toDecode;
}
StringBuffer decoded = new StringBuffer();
for (int i = 0, l = toDecode.length(); i < l; i++) {
if (matchesEncodedPattern(toDecode, i)) {
decoded.append(((char) Integer.parseInt(toDecode.substring(i + 2, i + 6), 16)));
i += 6;// then one added for the loop to mkae the length of 7
} else {
decoded.append(toDecode.charAt(i));
}
}
return decoded.toString();
}
}