Advertisement
chaibs

targil2-chars

Dec 12th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1. package myfirst;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class targil2 {
  6.  
  7.     public static void main(String[] args) {
  8.  
  9.         char d1, d2, d3;
  10.         int num = 0, n1 = 0, n2 = 0, n3 = 0;
  11.  
  12.         Scanner s = new Scanner(System.in);
  13.  
  14.         System.out.println("Please enter first number between (0-9):");
  15.         d1 = s.next().charAt(0);
  16.  
  17.         System.out.println("Please enter second number between (0-9):");
  18.         d2 = s.next().charAt(0);
  19.  
  20.         System.out.println("Please enter third number between (0-9):");
  21.         d3 = s.next().charAt(0);
  22.  
  23.         n1 = (d1 - '0');// the inserted digit minus 48 in ascii
  24.         n2 = (d2 - '0');// the inserted digit minus 48 in ascii
  25.         n3 = (d3 - '0');// the inserted digit minus 48 in ascii
  26.  
  27.         num = n1 * (10 * 10) + n2 * (10 * 1) + n3 * (10 / 10);// 16 base to 10 base
  28.  
  29.         System.out.println("The number is: " + num);// result
  30.  
  31.     }
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement