Question

In: Computer Science

java program that coverts base13 to decimal. without using array and methods.

java program that coverts base13 to decimal. without using array and methods.

Solutions

Expert Solution

import java.util.Scanner;

public class ConvertToDecimal {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter a Base 13 string: ");
        String base13 = in.next();
        int decimal = 0;
        char digit;
        for (int i = 0; i < base13.length(); i++) {
            digit = base13.charAt(i);
            decimal *= 13;
            if (digit >= '0' && digit <= '9')
                decimal += digit - '0';
            else if (digit == 'a' || digit == 'A')
                decimal += 10;
            else if (digit == 'b' || digit == 'B')
                decimal += 11;
            else if (digit == 'c' || digit == 'C')
                decimal += 12;
        }
        System.out.println("The decimal number for " + base13 + " is " + decimal);
    }
}


Related Solutions

Write a java program of a multiplication table of binary numbers using a 2D array of...
Write a java program of a multiplication table of binary numbers using a 2D array of integers.
Using Linked List, create a Java program that does the following without using LinkedList from the...
Using Linked List, create a Java program that does the following without using LinkedList from the Java Library. and please include methods for each function. Create a menu that contains the following options : 1. Add new node at the end of LL. ( as a METHOD ) 2. Add new node at the beginning of LL. ( as a METHOD ) 3. Delete a node from the end of LL. ( as a METHOD ) 4. Delete a node...
COP 2800, Java Programming Assignment 6-1 Using Java create a program using the “Methods” we covered...
COP 2800, Java Programming Assignment 6-1 Using Java create a program using the “Methods” we covered this week. come up with a “problem scenario” for which you can create a “solution”. Utilize any/all of the examples from the book and class that we discussed. Your program should be interactive and you should give a detailed statement about what the “description of the program – purpose and how to use it”. You should also use a “good bye” message. Remember to...
Using JAVA Write a program that uses a 2-D array to store the highest and lowest...
Using JAVA Write a program that uses a 2-D array to store the highest and lowest temperatures for each month of the year. The program should output the average high, average low, and highest and lowest temperatures of the year. Your program must consist of the following methods with their appropriate parameters: a.) getData: This method reads and stores the data in the 2-D array. b.) averageHigh: This method calculates and returns the average high temperature of the year. c.)...
Using Java, design a program that creates an array of Card objects, shuffles them, then recursively...
Using Java, design a program that creates an array of Card objects, shuffles them, then recursively sorts them by value and then recursively sorts them by value and suit You will need to create a Card class with the following two fields: • value (a String) • suit (a String) You may include any other fields, constructors, or methods as needed. Your single array will need to contain 52 card objects, one for each value of each suit. The values...
WITH using methods create an array with numbers
IN JAVA  Prompt 3:WITH using methods create an array with numbersint [] number = { 35, 68, 80, 34, 45, 79, 80};Display the numbers in the array using for loopDisplay the sumFind biggest element in the arrayDisplay the numers in the array with index numbersDisplay the numers using for loop in ascending order (sort)
Using Java language (in program NetBeans). 1) Using a 2 dimensional array Your company has 4...
Using Java language (in program NetBeans). 1) Using a 2 dimensional array Your company has 4 grocery stores. Each store has 3 departments where product presentation affects sales (produce, meat, frozen). Every so often a department in a store gets a bonus for doing a really good job. You need to create a program that keeps a table of bonuses in the system for departments. Create a program that has a two dimensional array for these bonuses. The stores can...
Write a program in Java to sort the given array using merge sort, quick sort, insertion...
Write a program in Java to sort the given array using merge sort, quick sort, insertion sort, selection sort and bubble sort based on the input from the user which sorting technique they wanted to use. Get the array size, array elements from the user, and also display the sorted array along with the name of the sorting technique used.
Java program by using array only. II. The NumberTile Game (Unchanged) Number tiles are squares with...
Java program by using array only. II. The NumberTile Game (Unchanged) Number tiles are squares with a number from 1 to 9 at each side. A “board” for the game is a sequence of number tiles satisfying this property:       The right side of each tile (except the last) = the left side of the next tile on the board There are 2 players in the game, both of which are the computer. Each player starts with a "hand" of...
Create a Java Program/Class named MonthNames that will display the Month names using an array. 1....
Create a Java Program/Class named MonthNames that will display the Month names using an array. 1. Create an array of string named MONTHS and assign it the values "January" through "December". All 12 months need to be in the array with the first element being "January", then "February", etc. 2. Using a loop, prompt me to enter an int variable of 1-12 to display the Month of the Year. Once you have the value, the program needs to adjust the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT