Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

The simple code I have prepared is here. Please help me.
20 digits are not supported in Java which is quite frustrating. Please help me complete this assignment.

 
Saloon Keeper
Posts: 3900
154
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Please help me.
I will be grateful to you for your this help.


Thank you so much.
 
Sheriff
Posts: 15525
263
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Take care of yours and please help me if you can.

Thank you so much.


 
Piet Souris
Saloon Keeper
Posts: 3900
154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Sagar,

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


 
Junilu Lacar
Sheriff
Posts: 15525
263
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Long.MAX_VALUE only goes up to 19 digits: 9_223_372_036_854_775_807L
 
Piet Souris
Saloon Keeper
Posts: 3900
154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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



You are so kind. Thank you so much. 🙏🙏🙏
 
Marshal
Posts: 25452
65
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
    Bookmark Topic Watch Topic
  • New Topic