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: 9's Complement Source Code

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

    Post 9's Complement Source Code

    Hi everyone,
    can you please share source code on how to get 9's complment of a given number (up to 4 digit number, ex 9's Compment when you enter a single digit up to 4 digit number. i tried the program below but it has errors.

    public class Main
    {
    public static void main(String[] args) {

    String new1 = Integer.toString(result1);
    String new2 = Integer.toString(result2);
    String new3 = Integer.toString(result3);
    String new4 = Integer.toString(result4);

    String newNN = New1 + New2 + New3 + New4;
    Int newN = Integer.parseInt(newNN);
    int firstAnswer = newNN + m ;

    String firstAnswer2 = Integer.toString(firstAnswer);
    String finalAnswer = Character.toString(firstAnswer2.charAt(0));
    String finalAns1 = Character.toString(firstAnswer2.charAt (1));
    String finalAns2 = Character.toString(firstAnswer2.charAt (2));
    String finalAns3 = Character.toString(firstAnswer2.charAt (3));
    String finalAns4 = Character.toString(firstAnswer2.charAt (4));
    String newNN = finalAns1 + finalAns2 + finalAns3 + finalAns4;

    Int newN2 = Integer.parseInt(newNN2);
    Int newN3 = Integer.parseInt(finalAnswer);
    Ins Answer = newN2 + newN3;

    System.out.println("Answer: " + answer + "\n"
    + "9's Complement of " + n + " is " + newNN);
    }
    }

  2. #2
    Junior Member
    Join Date
    Sep 2018
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post 9's Complement Source Code

    Hi Guys,

    Need Help.... appreciates any help from you guys. there are errors on the code


    public class Main
    {
    public static void main(String[] args) {

    String new1 = Integer.toString(result1);
    String new2 = Integer.toString(result2);
    String new3 = Integer.toString(result3);
    String new4 = Integer.toString(result4);

    String newNN = New1 + New2 + New3 + New4;
    Int newN = Integer.parseInt(newNN);
    int firstAnswer = newNN + m ;

    String firstAnswer2 = Integer.toString(firstAnswer);
    String finalAnswer = Character.toString(firstAnswer2.charAt(0));
    String finalAns1 = Character.toString(firstAnswer2.charAt (1));
    String finalAns2 = Character.toString(firstAnswer2.charAt (2));
    String finalAns3 = Character.toString(firstAnswer2.charAt (3));
    String finalAns4 = Character.toString(firstAnswer2.charAt (4));
    String newNN = finalAns1 + finalAns2 + finalAns3 + finalAns4;

    Int newN2 = Integer.parseInt(newNN2);
    Int newN3 = Integer.parseInt(finalAnswer);
    Ins Answer = newN2 + newN3;

    System.out.println("Answer: " + answer + "\n"
    + "9's Complement of " + n + " is " + newNN);
    }
    }

  3. #3
    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: 9's Complement Source Code

    it has errors.
    Please explain.
    Please copy the full text of the error message and paste it here. It has important info about the error.




    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. I need code source code for exam ,please
    By mehdi19 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 3rd, 2017, 03:21 AM
  2. Source Code
    By Alaa in forum Java Theory & Questions
    Replies: 3
    Last Post: August 3rd, 2013, 05:41 AM
  3. source code
    By bashor in forum What's Wrong With My Code?
    Replies: 7
    Last Post: April 6th, 2013, 07:33 PM
  4. Source code please
    By Gavin Fraser in forum Java Networking
    Replies: 2
    Last Post: September 17th, 2012, 03:46 PM
  5. need help with a new way of source code
    By Balger in forum Object Oriented Programming
    Replies: 15
    Last Post: August 26th, 2012, 01:41 PM