ClearAll["Global`*"]
$Assumptions = True; (* this means use defaults... *)
B[n_]=2(∫_0^1)(1-r)x Sin[n π x]\[DifferentialD]x

ClearAll["Global`*"]
$Assumptions =n ∈ PositiveIntegers;
B[n_]=2(∫_0^1)(1-r)x Sin[n π x]\[DifferentialD]x