Is the following Code correct, for calculating Decimal to Triskaidecimal and Triskaidecimal to Decimal, I hope this code is not right

import java.util.Scanner;
public class converter
    /* 1) Decimal To Triskaidecimal
        2) Triskaidecimal To Decimal
        public static void main(String ar[])
            int a, b;
            String s;
            System.out.println("Please Select:\n1)Decimal To Triskaidecimal.\n2)Tridecimal To Decimal.\n3)Exit.");
            Scanner input = new Scanner(;
            s = input.nextLine();
            System.out.println("You have Selected:" +s);
                case "1":
                System.out.println("Decimal To Triskaidecimal Conversion:");
                Scanner ip_Dec2Tri = new Scanner(;
                //BufferedReader br = new BufferedReader(new InputStreamReader(;
                System.out.println("Please Enter A Decimal Number To Convert to Triskaidecimal Number:");
                a = ip_Dec2Tri.nextInt();
                //String Dec_Hex = br.readLine();
                int triskaidecimal = (a%13);
                if (triskaidecimal==10)
                    System.out.println("The Decimal To Triskaidecimal is : A");
                else if (triskaidecimal==11)
                    System.out.println("The Decimal To TriskaiDecimal is : B");
                else if (triskaidecimal ==12)
                    System.out.println("The Decimal To TriskaiDecimal is : C");
                    System.out.println("The Decimal To Triskaidecimal is :"+triskaidecimal);

                case "2":
                System.out.println("Triskaidecimal To Decimal Conversion:");
                System.out.println("Please Enter a Triskaidecimal Number to Convert it into Decimal:");
                Scanner ip_Tri2Dec = new Scanner(;
                b = ip_Tri2Dec.nextInt();
                int decimal = (b*13);
                System.out.println("The Tridecimal To Decimal is : " +decimal);
                case "3":
                System.out.println("System is Quitting!!!\nThank you for using the converter\n");
                System.out.println("Please Provide the Correct Input\nTry again!");
            }//end of switch s


Recommended Answers

All 5 Replies

You can tell for yourself if it's right or not by testing it

Why do you hope it's not right?

@JamesCherrill I'd tested it, it only works for numbers, say for example if I want to convert a decimal to triskaideciman(base13) it works good for only numbers, say for example I want to convert 13A to decimal it is giving me an error message

You read the input for that as an int, and ints do not contain As Bs or Cs, so you get an error. You have to read that input as a String and deal with each character in turn - basically the reverse of the code you have for int -> 13.

ps Your code for int to base 13 doesn't seem to have a any logic for values >= 13

How to define a logic for converting a decimal number into triskaidecimal ? I've been looking in google but can't find it .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.