File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes string length, exponent problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "string length, exponent problems" Watch "string length, exponent problems" New topic

string length, exponent problems

Travis Gn

Joined: Sep 11, 2003
Posts: 19
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.

I need more help!
Elouise Kivineva
Ranch Hand

Joined: Feb 07, 2002
Posts: 154
The java tutorial can be found here:
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

Joined: Dec 10, 2001
Posts: 7023
Note that the Java API documentation can be found at

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
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
    Ranch Hand

    Joined: Jan 31, 2003
    Posts: 401
    Then there is Head First Java It's purty cool for beginners.

    I agree. Here's the link:
    subject: string length, exponent problems
    It's not a secret anymore!