Results 1 to 13 of 13
  1. #1
    Join Date
    Aug 2014
    Posts
    25
    Rep Power
    0

    Default how can I express * as a variable

    I'm trying to make a calculator and for how I am doing it i need to know how to show that *,-,+,/, are something the System needs to look for. don't me I am doing it wrong even if I am I still want to see if this works.If it is impossible to express those variables then please tell me,thank you.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: how can I express * as a variable

    *,-,+,/, are something the System needs to look for
    I assume that those special characters will be read into the program as Strings or as parts of Strings.
    The String class has methods to look for or compare Strings.
    Also some of the methods that use regular expressions might be useful.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Join Date
    Aug 2014
    Posts
    25
    Rep Power
    0

    Default Re: how can I express * as a variable

    ok cool! how would i write it as a string?

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: how can I express * as a variable

    To make a String in a program, enclose it in "s. For example: "A String"
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    Join Date
    Aug 2014
    Posts
    25
    Rep Power
    0

    Default Re: how can I express * as a variable

    wait so would i do * String; ?

    Edit- nvm i get what your saying kind of,can you give an example of how i would catagorize one of those special characters?

    Edit 2-nvm again,what keyword would i use for the "special characters"
    Last edited by DeathByFire223; 11-05-2014 at 01:30 AM.

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: how can I express * as a variable

    The special characters would be in Strings if the code was going to see and process them.
    If they are not in Strings, the compiler will process them.
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    Join Date
    Aug 2014
    Posts
    25
    Rep Power
    0

    Default Re: how can I express * as a variable

    then how do i make it so it counts like any other thing i do.for example- double example; or int a = 1; how do i make it so it counts as a varible?

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: how can I express * as a variable

    how do i make it so it counts as a varible?
    Please explain. What is the "it"?

    Look at the rules the compiler uses to determine if a word or token in the source is a variable name.

    In the statement:
    int aVar = 1;
    aVar would be a variable.
    If you don't understand my response, don't ignore it, ask a question.

  9. #9
    Join Date
    Aug 2014
    Posts
    25
    Rep Power
    0

    Default Re: how can I express * as a variable

    it meaning "the special characters"

    Edit- ohh...so what i want is the special characters to be able to count as the number 1 in your statement
    so i want it right here v
    ...............(keyword) *;
    or
    (keyword) 1 = *;

    and i want to know either the keyword that needs to be used or another method that needs to be used
    Last edited by DeathByFire223; 11-05-2014 at 04:33 AM.

  10. #10
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: how can I express * as a variable

    If you want to use any of the special characters like a *, it needs to be in a String: "*"
    If you don't understand my response, don't ignore it, ask a question.

  11. #11
    Join Date
    Aug 2014
    Posts
    25
    Rep Power
    0

    Default Re: how can I express * as a variable

    Quote Originally Posted by Norm View Post
    If you want to use any of the special characters like a *, it needs to be in a String: "*"
    Ok so what I am trying to do is if the user input in the console is *,+,/,or - then something will happen. I can show the code if you want me to.

    so basically-

    Java Code:
    double sign;
    System.out.print("enter expression sign: ")
    if (sign == *){
    }
    Edit 2- wait now i know what you are saying but i am stuck at another part.

    Java Code:
        double input1;
        String sign = ("sign");
        double input2;
        String B = ("/");
        String A = ("*");
        System.out.print("enter first number: ");
        input1 = bob.nextDouble();
        	
        System.out.print("enter expression sign: ");
        if (sign == A){
        System.out.print(""+ A);
        if (sign == B){
        System.out.print(""+ B);
        sign = bob.nextDouble();
    the second bob.nextDouble(); is red(the one that is = to sign)
    and bob is the scanner btw.
    Last edited by DeathByFire223; 11-05-2014 at 04:54 AM.

  12. #12
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: how can I express * as a variable

    In case Norm is asleep...'sign' is a String, and nextDouble returns a double.
    You want to use the one that returns a String, which is next()...(not nextLine() by the way, which is a cause of several problems).

    Also, when comparing Strings for equality you need to use the equals() method. Strings are objects, so == only checks if they are the exact same object in memory and not whether they are the logically equal.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  13. #13
    Join Date
    Aug 2014
    Posts
    25
    Rep Power
    0

Similar Threads

  1. MS SQL Express/JDBC
    By Toll in forum JDBC
    Replies: 1
    Last Post: 10-21-2012, 06:58 PM
  2. express string?
    By jiml in forum New To Java
    Replies: 2
    Last Post: 07-10-2012, 02:49 PM
  3. Express 240 as'Two hundred and forty'
    By j3sr in forum New To Java
    Replies: 2
    Last Post: 01-28-2010, 11:11 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
  •