• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

string length, exponent problems

 
Travis Gn
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just started using Java, I completed my homework assignment in VB, but now I want to do it in java.
Problem: What is the largest value of n for which 2to the nth power has fewer than 100 decimal digits. Also, fewer than 1000 decimal digits?
I don't know how to tell the length of a string, or a double, or what ever type I should be using for this problem?
I also don't know how to raise a number to a power? I guess just using a loop and multplying it again and again? It seems there should be a better way, but I can't find it.
The more help the better, any code examples are greatly appriciated. I seem to learn best from them.
 
Elouise Kivineva
Ranch Hand
Posts: 154
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The java tutorial can be found here:
http://java.sun.com/docs/books/tutorial/
The java 1.4.2 API tells you about all the various classes and the information (class members) and services (methods) they offer.
To get the length of a String the String class (java.lang.String) seems a logical place to look. Check out the methods (see "method summary") of the String class and see what you find.
To get an exponent you should look at the Math (java.lang.Math) class methods.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that the Java API documentation can be found at http://java.sun.com/apis.html
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As you're new to this Java programming, here is a list of free on-line Java tutorials and books that I have found useful that you might find useful as well.
  • Sun's Java Tutorial
  • Introduction to Computer Science using Java by Bradley Kjell
  • Introduction to Programming Using Java by David J. Eck
  • Dick Baldwin's Java Programming Tutorials
  • Interactive Programming In Java by Lynn Andrea Stein
  • Bruce Eckel's Thinking In Java
  •  
    Donald R. Cossitt
    buckaroo
    Ranch Hand
    Posts: 401
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Then there is Head First Java It's purty cool for beginners.
     
    I agree. Here's the link: http://aspose.com/file-tools
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic