Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Tim Cooke
• Paul Clapham
• Devaka Cooray
• Bear Bibeault
Sheriffs:
• Junilu Lacar
• Knute Snortum
• Liutauras Vilda
Saloon Keepers:
• Ron McLeod
• Stephan van Hulst
• Tim Moores
• Tim Holloway
• Piet Souris
Bartenders:
• salvin francis
• Carey Brown
• Frits Walraven

Please Help me finish my assignment- 20 digits number should B used but Java doesn't support it. :'(

Greenhorn
Posts: 4
Dear Developers,

I need your sincere help. I am creating a program that calculates the fun parts of friendship between 2 friends based on their cellphone numbers.

20 digits are not supported in Java which is quite frustrating. Please help me complete this assignment.

Saloon Keeper
Posts: 3900
154
• 1
hi Sagar,

welcome to the Ranch and enjoy the stay!

How many digits does a celphonenumber has? You are adding the two, but if both numbers contain at most 16 digits, the sum will always fit in a Long.

Sagar Lama
Greenhorn
Posts: 4
Dear Sir Piet Souris,

Thank you so much. I have no words to appreciate your kind reply.
The cellphone number is of 10 digits each.
I need to multiply them as well.
I am very new in programming.
I will be grateful to you for your this help.

Thank you so much.

Sheriff
Posts: 15525
263
• 1
Have you looked at BigInteger? It supports values up to +2^Integer.MAX_VALUE, which is many more digits than 20.

Also, while a telephone number usually consists of just numbers, it's usually not represented with a number but with a String instead.

Junilu Lacar
Sheriff
Posts: 15525
263
• 1
Line 54 contains a logic error. In Java, = is an assignment operator whereas == will compare values for primitive types and references for object types.

Sagar Lama
Greenhorn
Posts: 4
Dear Junilu Lacar,

Thank you very much for replying.
The assignment given by instructor is to do all the operations of all datat types.
I must use Long data type and different operators.
I don't know what to do. I have done other data type with basuc calculations to student's marks caculating to others for other data types.

String datatype also didn't support this operation of calculating with 10 digits cell phone numbers.
If it would support I would nake different program with Long data type.

You are so kind and sweet thank you for teaching me = and == difference.

Thank you so much.

Piet Souris
Saloon Keeper
Posts: 3900
154
hi Sagar,

well using longs is'nt a problem. Run this code:

Junilu Lacar
Sheriff
Posts: 15525
263
Long.MAX_VALUE only goes up to 19 digits: 9_223_372_036_854_775_807L

Piet Souris
Saloon Keeper
Posts: 3900
154
Yes, but as the code snippet shows, the product of two phonenumbers is at most 18 digits long (unless a phonenumber contains the countrycode as well, or that they can start other than with 06).

Sagar Lama
Greenhorn
Posts: 4

Piet Souris wrote:hi Sagar, . . . Run this code . . .

You are so kind. Thank you so much. 🙏🙏🙏

Marshal
Posts: 25452
65

Junilu Lacar wrote:Have you looked at BigInteger? It supports values up to +2^Integer.MAX_VALUE, which is many more digits than 20.

No kidding. If my calculations are correct, it's pretty close to 7,133,786,263 digits.

Rancher
Posts: 4549
47
• 1

Piet Souris wrote:Yes, but as the code snippet shows, the product of two phonenumbers is at most 18 digits long (unless a phonenumber contains the countrycode as well, or that they can start other than with 06).

My mobile number is 11 digits long, 10 if you ignore the leading 0.
It's very country dependent.

 There will be plenty of time to discuss your objections when and if you return. The cargo is this tiny ad: Two software engineers solve most of the world's problems in one K&R sized book https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton