V
V
Vlad_Radigin2018-04-23 08:26:08
Java
Vlad_Radigin, 2018-04-23 08:26:08

How to write a program in java that will receive a number from the user, which will then be displayed in hexadecimal form?

How to write a java console application that will ask the user for a number, which will then output to the console in hexadecimal form?
For example, the user entered the number 10, and the application will display this number, only in hexadecimal form?
If this can be done, please tell me how.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
hHup, 2018-04-23
@TopMetaFizick

import java.util.Scanner;

public class myClass {

    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        System.out.println("Введите число: ");
        int n=scanner.nextInt();

        System.out.println("В шестнадцаричном счислении: " +Integer.valueOf(String.valueOf(n), 16));




    }

}

A
Andrey, 2018-04-23
@poslannikD

Approximate console version
1) create BufferedReader reader .....
2) get data from readera and convert to
int int dec = Integer.parseInt(reader.readLine())
3) output data to console and convert System. out.println( Integer.toString(dec, 16).toUpperCase())
Of course, you still need to wrap it in a try-catch. And close I/O streams

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question