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 6 of 6

Thread: whats wrong with this code....it says, 'the operator / is undefined for z=1.0-"A" / 2.0

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

    Default whats wrong with this code....it says, 'the operator / is undefined for z=1.0-"A" / 2.0

    import java.lang.System;
    public class Check01D {

    public static void main(String[] args) {
    // TODO Auto-generated method stub

    double z;
    z = 1.0 - "A" / 2.0 + 1.0 % 2.0;
    double y;
    y = 2.0-z*z/2.0;
    double x;
    x = 1.0-2.0*y/z;

    System.out.println("The value of x is:" + x);

    }

    }


  2. #2
    Member Kewish's Avatar
    Join Date
    Apr 2013
    Location
    Australia
    Posts
    116
    Thanks
    10
    Thanked 17 Times in 14 Posts

    Default Re: whats wrong with this code....it says, 'the operator / is undefined for z=1.0-"A" / 2.0

    You probably want the int value of a char. Look at your code, what are are you asking the value of?

  3. #3
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,465
    My Mood
    Grumpy
    Thanks
    0
    Thanked 158 Times in 149 Posts

    Default Re: whats wrong with this code....it says, 'the operator / is undefined for z=1.0-"A" / 2.0

    How do you expect to divide a String?
    Improving the world one idiot at a time!

  4. #4
    Member
    Join Date
    May 2013
    Posts
    96
    My Mood
    Amused
    Thanks
    16
    Thanked 9 Times in 9 Posts

    Default Re: whats wrong with this code....it says, 'the operator / is undefined for z=1.0-"A" / 2.0

    Chars are only supposed to go in single quotes. Double quotes are for strings.

  5. The Following User Says Thank You to mstabosz For This Useful Post:

    guled (September 19th, 2013)

  6. #5
    Junior Member
    Join Date
    Sep 2013
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: whats wrong with this code....it says, 'the operator / is undefined for z=1.0-"A" / 2.0

    Quote Originally Posted by Kewish View Post
    You probably want the int value of a char. Look at your code, what are are you asking the value of?
    so guide me through because am a beginner, I want the value of x to be displayed. ..thanks

    --- Update ---

    thanks

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

    Default Re: whats wrong with this code....it says, 'the operator / is undefined for z=1.0-"A" / 2.0

    Quote Originally Posted by guled View Post
    so guide me through because am a beginner
    Reread post numbers 2 and 3, compare the advice to your code, fix the problem

Similar Threads

  1. "Ask a Question" menu item dumps into "What's Wrong With My Code?"
    By GregBrannon in forum Forum Updates & Feedback
    Replies: 1
    Last Post: August 6th, 2013, 03:37 AM
  2. HOW TO USE THE OPERATOR "this" in JAVA(OOP)?
    By BALLISLIFE in forum Object Oriented Programming
    Replies: 3
    Last Post: July 31st, 2013, 08:58 PM
  3. Replies: 8
    Last Post: May 6th, 2013, 07:53 AM
  4. Replies: 3
    Last Post: December 7th, 2011, 01:03 AM
  5. [SOLVED] Conditional Operator "?:" not compiling
    By mwardjava92 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 1st, 2011, 05:40 PM