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: How to subtract from the total length of an array

  1. #1
    Junior Member
    Join Date
    Jan 2019
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to subtract from the total length of an array

    I have an array named shop which has a length of 10.

    char shop[][] = new char[10][10]
    so my shop.length is 10

    if (colshop == 9)
    In the above line, I have hard-coded the value to be 9, Instead, I want to subtract 1 from shop.length.

    If I do if (colshop == (shop.length - 1)) ,it is not working.Please be patient as I am new to java. How do I do it so that I get the value of 9 as i do not want to hard code the value 9

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,328
    Thanks
    53
    Thanked 2,393 Times in 2,347 Posts

    Default Re: How to subtract from the total length of an array

    Please read: The problems with cross-posting
    Stop posting on more than one site without providing links to the other sites.
    You may be banned if another cross-posting.

    Also posted at: https://www.dreamincode.net/forums/t...h-of-an-array/

    and here: https://coderanch.com/t/706661/java/...l-length-array
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Sep 2018
    Location
    Virginia
    Posts
    284
    My Mood
    Cool
    Thanks
    0
    Thanked 38 Times in 36 Posts

    Default Re: How to subtract from the total length of an array

    It works for me. You must be having other problems. But you didn't really provide much information. Providing a few lines of code out of context does not help anyone understand the real issue.

    Regards,
    Jim

Similar Threads

  1. [SOLVED] Return an array of Pairs that have the same length as the input array of Strings.
    By hemla in forum Object Oriented Programming
    Replies: 3
    Last Post: August 8th, 2013, 08:17 AM
  2. Replies: 6
    Last Post: October 7th, 2011, 07:50 AM
  3. Replies: 5
    Last Post: May 24th, 2011, 10:39 AM
  4. max length of an array?
    By qsbladey in forum Collections and Generics
    Replies: 4
    Last Post: April 3rd, 2011, 11:17 AM
  5. Finding the length of a two dimensional array
    By petemyster in forum Java Theory & Questions
    Replies: 2
    Last Post: December 12th, 2010, 09:21 PM