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

Thread: Problem with byte and short data type

  1. #1
    Junior Member
    Join Date
    Jun 2020
    Posts
    11
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default Problem with byte and short data type

    Hello,

    When I use byte and short for number method, I have an error. (when I change byte to int and short to int, the problem was fixed)

    Thanks


    Image:
    https://ibb.co/ZWY0QSq

    and error is:

    Exception in thread "main" java.lang.Error: Unresolved compilation problem:
    The method number(byte, long, double, short, short) in the type MainClass is not applicable for the arguments (int, long, double, int, int)

    at MainClass.main(MainClass.java:9)

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Problem with byte and short data type

    The method number(byte, long, double, short, short) in the type MainClass is not
    applicable for the arguments (int, long, double, int, int)
    The method number is defined to take parameters of the type shown in the error message. The code that calls the number method needs to use those data types that match.

    The code might compile if the wrong types were cast to int. Cast by adding (int) in front of the variable name.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    shervan_360 (July 8th, 2020)

  4. #3
    Junior Member
    Join Date
    Jun 2020
    Posts
    11
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default Re: Problem with byte and short data type

    Thank you,

    But why should we cast to int? I want to use byte and short.

    Method call is:
    number(19,52608968L,2828282d,373,28337);

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Problem with byte and short data type

    Sorry, the cast I suggested could be backwards. Did you try to cast the args that are being passed to be the same as the ones the method requires?
    If you don't understand my answer, don't ignore it, ask a question.

  6. The Following User Says Thank You to Norm For This Useful Post:

    shervan_360 (July 8th, 2020)

  7. #5
    Junior Member
    Join Date
    Jun 2020
    Posts
    11
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default Re: Problem with byte and short data type

    Quote Originally Posted by Norm View Post
    Sorry, the cast I suggested could be backwards. Did you try to cast the args that are being passed to be the same as the ones the method requires?
    Thank you,

    Yes,
    Byte (age) is : 19
    Short (codeTelephone) is :373
    Short (factorPlastic) is: 28337

    import java.util.*;
     
    public class MainClass
     {
      public static void main(String[] args)
       {
        string("مهدی", "پورغزاوی", "شلیل", "ایران");
        System.out.println("***************");
        number(19,52608968L,2828282d,373,28337);
        modelPhone('%');
       }
     
     
      public static void string(String name, String family, String fruit, String country)
       {
        System.out.println("نام: " + name + " نام خانوادگی: " + family + " نام میوه مورد علاقه: " + fruit + " نام کشور: " + country);
       }
     
      public static void number(byte age, long codeMelli,
    		  double numberphone, short codeTelephone, short factorPlastic)
       {
        if (age >= 19 && age < 20)
         {
          System.out.println("سن شما : " + age + " است");
         }
        else if (age == 20)
         {
          System.out.println("سن شما :" + age + " است");
         }
        else if (age < 19)
         {
          System.out.println("سن شما درست نیست و شما بزرگتر از 19 هستین");
         }
        else 
         {
          System.out.println("سن وارد شده :" + age + " درست نیست");
         }
        if (codeMelli == 5260869968L)
         {
          System.out.println(" کد ملی وارد شده: " + codeMelli + " صحیح است");
         }
        else
         System.out.println(" کد ملی وارد شده: " + codeMelli + " صحیح است");
     
     
        if (numberphone == 09376287204d)
         {
          System.out.println("شماره تلفن شما :" + numberphone + " صحیح لست");
         }
        else
         {
          System.out.println("شماره تلفن شما: " + numberphone + " غلط است");
         }
        if (codeTelephone == 4282)
         {
          System.out.println(" کد تلفن شهرستان شما: " + codeTelephone + " صحیح است");
         }
        else
         System.out.println(" کد تلفن شهرستان شما: " + codeTelephone + " غلط است");
     
        if (factorPlastic == 18000)
         {
          System.out.println("قیمت فاکتور پلاستیک سفید دسته دار : " + factorPlastic + " است");
         }
        else if (factorPlastic < 18000)
         {
          System.out.println("قیمت پلاستیک کمتر از 18000 تومن نیست");
         }
        else if (factorPlastic > 18000)
         {
          System.out.println("قیمت پلاستیک بیشنر از 18000 تومن نیست");
         }
        else
         {
          System.out.println("قیمت زده شده اشتباه است");
         }
        System.out.println("سن شما: " + age + " کد ملی: " + codeMelli + " شماره تلفن: " + numberphone + " کد تلفن شهر: " + codeTelephone + " قیمت ردز عمده پلاستیک: " + factorPlastic);
        System.out.println("■■■■■■■■■■■■■■■■■■■■");
       }
     
      public static char modelPhone(char model)
       {
        if (model >= 65 && model <= 90)
         {
     
          System.out.println("مدل شما حرف " + model + " بزرگ است");
     
         }
        else if (model >= 97 && model <= 122)
         {
          System.out.println("مدل شما حرف :" + model + " کوچک است");
         }
        else if (model >= 48 && model <= 57)
         System.out.println("مدل شما: " + model + "اعداد 0 تا 9 هستن");
        else
         {
          System.out.println("مدل وارد شده غلط است");
         }
        return 36;
       }
     
      public static void bool(boolean codeMelli, boolean numberPhone, boolean codeTelephone, boolean factorPlastic, boolean age)
       {
     
       }
     }

  8. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Problem with byte and short data type

    Did you try casing the arguments in the call to number to the required types?
    If you don't understand my answer, don't ignore it, ask a question.

  9. The Following User Says Thank You to Norm For This Useful Post:

    shervan_360 (July 8th, 2020)

  10. #7
    Junior Member
    Join Date
    Jun 2020
    Posts
    11
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default Re: Problem with byte and short data type

    Thank you and solved my problem.
    number((byte)2,(long)8L,(double)2d,(short)32,(shor t)2)

Similar Threads

  1. Can an int array contain a short or byte?
    By snyderthing in forum Java Theory & Questions
    Replies: 8
    Last Post: October 14th, 2018, 08:56 PM
  2. Can an int array contain a short or byte?
    By snyderthing in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 12th, 2018, 01:37 PM
  3. [SOLVED] Adding two byte/ short variables
    By ranjithfs1 in forum Java Theory & Questions
    Replies: 1
    Last Post: May 26th, 2012, 04:31 AM
  4. Replies: 2
    Last Post: February 17th, 2012, 02:13 AM
  5. Replies: 4
    Last Post: September 5th, 2010, 10:29 AM