Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2. public class DeziHexa {
  3.  
  4.     public static void main(String[] args) {
  5.    
  6.         char hexadezimalzeichen[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};  
  7.         String hexadezimale = "";
  8.        
  9.         Scanner scanner = new Scanner (System.in);
  10.        
  11.         int dezimale = scanner.nextInt();
  12.         if(dezimale >= 0) {
  13.            
  14.             while(dezimale > 0) {
  15.                 int rest = dezimale % 16;
  16.                 hexadezimale = hexadezimalzeichen[rest] + hexadezimale;
  17.                
  18.                 dezimale /= 16;
  19.                
  20.             }
  21.             System.out.println(hexadezimale);
  22.         }else
  23.             System.out.println("ungültige Eingabe");
  24.  
  25.     }
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement