Problem: Jack Stealer has been suppressing his income from the Feds to save taxe
ID: 3569049 • Letter: P
Question
Problem: Jack Stealer has been suppressing his income from the Feds to save taxes. After several years of chasing him down, they finally get hold of his computer, and his spreadsheets, where he stores all his transactions. Much to their dismay, he had encrypted the numbers in his spreadsheet. Since you are an expert programmer, the Feds bring you in the team, to decrypt his financial transactions. You do not take too long to figure out that he has been using a very simple scheme to represent numbers. He uses
Explanation / Answer
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.lang.Double;
public class Decrypt {
private static String conversionTable[][] = {
{"a", "0"},
{"b", "1"},
{"c", "2"},
{"d", "3"},
{"e", "4"},
{"f", "5"},
{"g", "6"},
{"h", "7"},
{"i", "8"},
{"j", "9"},
};
public static double decrypt(String encryptedNumber) {
///{
//write your code here
//start
int n = encryptedNumber.length();
double number=0;
double dec = 10;
boolean decimalReached = false;
for (int i = 0; i < n; i++)
{
if(encryptedNumber.charAt(i) == '.')
{
decimalReached = true;
continue;
}
double no = encryptedNumber.charAt(i) - 97;
if(!decimalReached)
{
number = number*10.0 + (no);
}
else
{
number = number + (no/dec);
dec = dec*10;
}
}
return number;
//end
///}
}
public static void main(String arg[]){
Scanner scanner =new Scanner(System.in);
System.out.println("Enter the string to decrypt:");
String input=scanner.next();
System.out.println("Number after decryption is:"+decrypt(input));
}
}
------------------------------------------------------------------------------
OUTPUT
Enter the string to decrypt:
b.aab
Number after decryption is:1.001
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.