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.

Results 1 to 3 of 3

Thread: Simple maths equations

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Simple maths equations

    Hello I am brand new to Java having only programed in Python before. I am trying to write a Java program that displays the result of(1.3x2.4)-(2.6x4)/(45.5-6.7).
    What I have tried...
    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    package assignment1.pkg3b;
     
     
    /**
     *
     * @author Pavilion
     */
    public class Assignment13b {
     
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            sum = (1.3*2.4)-(2.6*4)/(45.5-6.7);      
     
     
     
        }
     
    }


    The error returned says- create filed "sum" in assignment.pkb3b.Assignment13b, creat parameter "sum", create local variable "sum".

    Thank you in advance as I same I am brand new to this language.
    Last edited by jps; September 17th, 2013 at 04:24 PM. Reason: code tags


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 262 Times in 231 Posts

  3. #3
    Junior Member
    Join Date
    Sep 2013
    Posts
    18
    Thanks
    3
    Thanked 3 Times in 1 Post

    Default Re: Simple maths equations

    In python, variables do not need to be declared as their datatype is inferred.

    In java, variables must be declared with a type. You can assign sum as an int or a double.

    You'd also need to print the result to the console. In python you'd just type 'print sum', in java you'd use print or println. The syntax is slightly different than python, but this type of information is very easy to find.

Similar Threads

  1. [SOLVED] Random maths operator generation
    By dk87 in forum What's Wrong With My Code?
    Replies: 11
    Last Post: April 8th, 2013, 06:11 AM
  2. Slopes/ Equations of a Line extended Code
    By Eoing008 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 6th, 2012, 07:04 AM
  3. How do i make two equations have to be equal?
    By jamesR in forum Java Theory & Questions
    Replies: 2
    Last Post: October 3rd, 2012, 12:10 AM
  4. Question. Lots of Maths!
    By djl1990 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: October 28th, 2011, 10:57 AM
  5. Replies: 1
    Last Post: June 17th, 2011, 06:01 PM

Tags for this Thread