Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a function in java that works like SUBSTRING function but for integers?

Tags:

java

is there a function in java that works like SUBSTRING function but for integers. Like for example the user's input is 456789, I want to break it into two part and put them into different variable. and divide them. for example,

user's input : 456789

the first 3 numbers will be in variable A.

the last 3 numbers will be in variable B.

pass = A/B;

can someone help me how can I do this,

thanks.

like image 367
user3818144 Avatar asked Mar 12 '26 06:03

user3818144


1 Answers

Use integer division and the modulus operator:

int input = 456789;
int a = input / 1000;
int b = input % 1000;
like image 77
clcto Avatar answered Mar 14 '26 20:03

clcto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!