Results 1 to 10 of 10
  1. #1
    Join Date
    Feb 2017
    Posts
    4
    Rep Power
    0

    Default New Learner Question

    Hi guys, I have been trying to learn java for a couple of weeks and managed to get some questions from my boyfriends old uni papers. I have been working through them and I have got stuck on a one that I can't quite work out. I was hoping someone could point me in the right direction please.

    The question says. Create a Java program that uses two integers (number1 and number2) to calculate the result of number 1 squared plus number 2 squared.

    Now I though it was something like Math.pow(number1*2) but I can't get it working, sorry about being so thick. It is brand new to me.

    Thanks guys Emma.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: New Learner Question

    If you really want to use the Math.pow() function, then it takes two arguments, the number and the power (your * should be a ,). But for something
    like this (where you are using integers), I would just write out the actual expression using multiplication and addition.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    Join Date
    Feb 2017
    Posts
    4
    Rep Power
    0

    Default Re: New Learner Question

    Hi Jim, could you give me an example of how to set that out please, sorry I am really new to this.

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: New Learner Question

    First, as someone new to Java, you should bookmark this -> Java Platform SE 8
    It is the API and has the documentation on all methods. Here is the Math class -> Math (Java Platform SE 8 )

    Math.pow(x,y) raises x to the yth power and returns the result.

    Or to square a number, just do

    int a = 10;
    int sqr = a * a; // sqr is now 100.

    EDIT: I forgot to include this link which is also useful -> http://docs.oracle.com/javase/tutorial/index.html

    Regards,
    Jim
    Last edited by jim829; 02-07-2017 at 05:01 PM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  5. #5
    Join Date
    Feb 2017
    Posts
    4
    Rep Power
    0

    Default Re: New Learner Question

    Ok I am in over my head here, I can't understand any of this. Think I will start learning something a little easier, thanks.

  6. #6
    cronnin is offline Member
    Join Date
    Jan 2017
    Posts
    38
    Rep Power
    0

    Default Re: New Learner Question

    Did you write that equation on a paper?

  7. #7
    Join Date
    Feb 2017
    Posts
    4
    Rep Power
    0

    Default Re: New Learner Question

    Quote Originally Posted by cronnin View Post
    Did you write that equation on a paper?
    Hi, I don't really understand equations, I just wanted to try and do a few questions but I cant follow the answers given in here or any of the information from the links to other websites. I will just have to forget Java, thanks.

  8. #8
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,993
    Rep Power
    9

    Default Re: New Learner Question

    Quote Originally Posted by NewLearnerEmma View Post
    Hi, I don't really understand equations, I just wanted to try and do a few questions but I cant follow the answers given in here or any of the information from the links to other websites. I will just have to forget Java, thanks.
    Don't give up so quick. There are lots of people willing to help here.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  9. #9
    scarecrowkid is offline Member
    Join Date
    Dec 2016
    Posts
    20
    Rep Power
    0

    Default Re: New Learner Question

    I hear python is the new language that students pick up first. You might want to look into some python tutorials/courses to take if you are giving up on Java

  10. #10
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: New Learner Question

    Perhaps. But every programming language I have every studied (sans APL) has similar operators and method, function, or subroutine calls. So the OP would still need to understand that in any language. Even some of the basic contructs of Java can be learned within the static main context without understanding the nature of a class or object. But I agree she (everyone actually) should become familiar with programming at its basic level.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Learner questions!!!
    By Firstin in forum New To Java
    Replies: 3
    Last Post: 01-28-2014, 10:21 AM
  2. [Learner] Little project
    By N0VA in forum Jobs Wanted
    Replies: 0
    Last Post: 12-09-2010, 11:07 PM
  3. pong game with reinforcement learner
    By jackdalton in forum New To Java
    Replies: 7
    Last Post: 11-12-2010, 07:10 PM
  4. Java Learner
    By Natty in forum New To Java
    Replies: 2
    Last Post: 04-14-2010, 07:15 AM
  5. new learner..
    By coolymeimei in forum New To Java
    Replies: 1
    Last Post: 04-09-2009, 11:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •