Int multiply int a int b a b где ошибка

«The following code is not executing properly, try to figure out why.»

public class CustomMath {
public static int multiply(int a, string b) {
    return a * b;
}
}

Here’s my solution:

public class CustomMath 
{
    Int i = 1;

    public static int multiply(int a, int b) 
    {
    return a * b;
    }
}

I’m still plugging away at it started looking at operator overloading. Still catching the fail so I guess I am still not seeing it or failing to understand something about using operator overloading. Is the operator overloading my only issue or is my return syntax off?

using system;

public class CustomMath
{
    public static int operator *(int a, string b) 
    {
        return a * b;
    }
}

So I’m looking into binary operators, pretty sure my issue is that I am not expressing the int and string properly.

Servy's user avatar

Servy

202k26 gold badges331 silver badges447 bronze badges

asked Aug 13, 2015 at 15:05

jmallinga's user avatar

5

from the error that you’ve got you should understand that the function signiture is wrong and you need to change the type of b (string) to be int. so your code would be:

public class CustomMath 
{
    public static int multiply(int a, int b) 
    {
        return a * b;
    }
}

answered Aug 16, 2015 at 7:14

silver's user avatar

silversilver

1,6031 gold badge20 silver badges32 bronze badges

1

Your operator overload won’t work, because in order to overload the multiplication operator, at least one of the operands has to be of a user-defined type.

The thing is, you don’t need overloading at all. There are methods in the .NET framework designed specifically to «extract» an integer from a string, which is what you should do before multiplying anything. There are two easy ways of achieving this: int.Parse and int.TryParse. Just take a look at the MSDN documentation to figure out how they work and choose the best in your specific scenario.

And here is int.Parse in action:

string s = "5";
int i = int.Parse(s);
int j = i + 10 // At this point j = 15

answered Aug 14, 2015 at 18:42

Kapol's user avatar

KapolKapol

6,3633 gold badges21 silver badges46 bronze badges

Информатика Студенческий Агапит Агапит
03.13.19

Решено

26

ОТВЕТЫ

Int multiply(int a, int b) { return (a*b); }

246

Отв. дан
2019-03-13 01:24:39

Не уверен в ответе?

Найди верный ответ на вопрос ✅ «Найти ошибку int multiply (int a, int b) { a * b; } …» по предмету 📙 Информатика, а если ответа нет или никто не дал верного ответа, то воспользуйся поиском и попробуй найти ответ среди похожих вопросов.

Искать другие ответы

где ошибка

.

package com.javarush.task.task06.task0612;

/*
Калькулятор
*/

public class Calculator {
public static int plus(int a, int b) {
int plus = a+b;
//напишите тут ваш код
return plus;
}

public static int minus(int a, int b) {
int minus = a-b;
//напишите тут ваш код
return minus;
}

public static int multiply(int a, int b) {
int multipl = a*b;
//напишите тут ваш код
return multipl;
}

public static double division(double a, double b) {
double divisi =a/b;

//напишите тут ваш код
return divisi;
}

public static double percent(int a, int b) {
int q = a/100;
int persent = q*b;

//напишите тут ваш код
return persent;
}

public static void main(String[] args) {

}
}


12

1 ответ:



0



0

Int multiply(int a, int b) { return (a*b); }

Читайте также

Var s: integer;
begin
s := random(1000)+2;
writeln(s);
if (s mod 2 = 0) then writeln(‘Четное.’)
else
writeln(‘Нечетное’)
<span>end.</span>

Var a,b,c,d:integer;begind:=0;a:=0;b:=0;c:=0;beginreadln(a);readln(b);readln(c);d:=a+b+c;if d > 3 thenbeginwriteln(‘A’,a-1) ;writeln(‘B’,b-1);writeln(‘C’,c-1);end;elsea:=a*a;b:=b*b;c:=c*c;end;writeln(‘A’,a) ;writeln(‘B’,b);writeln(‘C’,c);end. / в коде ошибка (

529 в 16-ричной системе будет равно 211

f1 = A
f2 = B
f3=C
f4=D
f5= E

Var n,s,i:integer;
begin
write(‘N=’); readln(n);
s:=0;
for i:=1 to n do s:=s+2*i-1;
writeln(‘S=’,s,’  N^2=’,n*n);
<span>end.</span>

Возможно, вам также будет интересно:

  • Insurgency ошибка steam validation rejected
  • Insurgency sandstorm ошибка при запуске
  • Insurgency sandstorm ошибка античита
  • Insurgency sandstorm ошибка unreal
  • Insufficient privileges ошибка стим

  • Понравилась статья? Поделить с друзьями:
    0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии