Advertisement
Ruhan_DIU

Problem A -VJ CONTEST

Oct 5th, 2018
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. import java.math.BigInteger;
  2. import java.util.Scanner;
  3.  
  4.  
  5.  
  6. import static sun.nio.ch.IOStatus.EOF;
  7.  
  8.  
  9. public class Main {
  10.  
  11.  
  12. public static void main(String[] args) {
  13. Scanner input = new Scanner(System.in);
  14.  
  15.  
  16. for (int i = 0; i < i+1; i++) {
  17. String num=input.next();
  18. char c=num.charAt(0);
  19. String s=String.valueOf(c);
  20. if(s.equals("-")){
  21. break;
  22. }else{
  23. String check="";
  24. if(num.length()>2) {
  25. char cc = num.charAt(1);
  26. String ss = String.valueOf(cc);
  27. check=s+ss;
  28. }
  29.  
  30.  
  31. if(check.equals("0x")){
  32. String v="";
  33. for (int j = 2; j <num.length() ; j++) {
  34. char cx=num.charAt(j);
  35. String sx=String.valueOf(cx);
  36. v=v+sx;
  37. }
  38. Integer dec=Integer.parseInt(v,16);
  39. System.out.println(dec);
  40. }else{
  41. Integer hex=Integer.valueOf(num);
  42. String hexa=Integer.toHexString(hex);
  43. hexa=hexa.toUpperCase();
  44. String p="0x";
  45. hexa=p+hexa;
  46. System.out.println(hexa);
  47. }
  48.  
  49.  
  50.  
  51.  
  52. }
  53.  
  54.  
  55.  
  56. }
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement