Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 2 of 2 FirstFirst 12
Results 26 to 31 of 31

Thread: Math.pow

  1. #26
    Junior Member
    Join Date
    Jul 2012
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Math.pow

    Quote Originally Posted by Norm View Post
    Is Xray the name of a variable? If so you need to define it and give it a value.
    Or did you want it to be a String? If so enclose it in "s.
    I'm not sure how to do this or where to put it.

  2. #27
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Math.pow

    What are you trying to do in the if statement?
     if ( s == XRay )
    If you don't understand my answer, don't ignore it, ask a question.

  3. #28
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Math.pow

    how to do this or where to put it.
    Please be more specific and not use words like this and it. I can't read your mind.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #29
    Junior Member
    Join Date
    Jul 2012
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Math.pow

    How do you define XRay, I do not know how to put that code in or where exactly to put it. I don't understand the difference between a variable and a string.

  5. #30
    Junior Member
    Join Date
    Jul 2012
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Math.pow

    Alright I've almost got it, all I need to do now is define XRay as the password.

        import java.util.Scanner;
     
        public class Password{
            public static void main(String[] args) {
     
          Scanner kbReader = new Scanner(System.in);
          System.out.println("Enter your password. ");
          String myPassword = kbReader.nextLine();
     
     
          if ( myPassword == "XRay" )
          System.out.println("Password entered successfully.");
     
          else
          System.out.println("Incorrect password.");
          }
        }

  6. #31
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Math.pow

    if ( myPassword == "XRay" )
    New topic: comparing the contents of objects. Strings are objects. If you want to compare the contents of two objects you need to use the equals() method:
    myPassword.equals( "XRay" )
    If you don't understand my answer, don't ignore it, ask a question.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. If-Else Statement and Math
    By mikecancelosi in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 3rd, 2012, 01:31 AM
  2. Math.Random()
    By xionyus in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 26th, 2011, 10:22 PM
  3. For the Math Majors
    By mszyndlar in forum Java Theory & Questions
    Replies: 0
    Last Post: October 18th, 2011, 04:40 PM
  4. Confusion with Math.toDegrees() and Math.toRadians(). Please help.
    By marksquall in forum Java Theory & Questions
    Replies: 3
    Last Post: June 23rd, 2011, 01:28 AM
  5. Math in Java?
    By [Kyle] in forum Java Theory & Questions
    Replies: 3
    Last Post: September 23rd, 2009, 12:21 PM