Hello guys, i have a question the im struggling to solve by myself and it goes like that:
The program will read from the user 3 notes from type char which are digits.
The program will create variable from type int that will consist the digits that will become a number.
The program will print the number on the screen.
E.g- the 3 digits are : 4,5,6 and the number is 456.
I have tried to write the following code:
import java.util.Scanner;
public class Exercise_2
{
public static void main(
String[]args)
{
Scanner scan= new Scanner(System.in);
char ch1,ch2,ch3;
System.out.println("Enter 3 digits:");
ch1=scan.next().charAt(0);
ch2=scan.next().charAt(0);
ch3=scan.next().charAt(0);
int result;
result=(100*ch1)+(10*ch2)+(1*ch3);
System.out.println(result);
}
}
But the program dont give the result i want to get and i dont know what is the problem.
please help me