Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.math.BigInteger;
- import java.util.Scanner;
- import static sun.nio.ch.IOStatus.EOF;
- public class Main {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- for (int i = 0; i < i+1; i++) {
- String num=input.next();
- char c=num.charAt(0);
- String s=String.valueOf(c);
- if(s.equals("-")){
- break;
- }else{
- String check="";
- if(num.length()>2) {
- char cc = num.charAt(1);
- String ss = String.valueOf(cc);
- check=s+ss;
- }
- if(check.equals("0x")){
- String v="";
- for (int j = 2; j <num.length() ; j++) {
- char cx=num.charAt(j);
- String sx=String.valueOf(cx);
- v=v+sx;
- }
- Integer dec=Integer.parseInt(v,16);
- System.out.println(dec);
- }else{
- Integer hex=Integer.valueOf(num);
- String hexa=Integer.toHexString(hex);
- hexa=hexa.toUpperCase();
- String p="0x";
- hexa=p+hexa;
- System.out.println(hexa);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement