2013-10-30 24 views
3

有一些我试图修复一遍又一遍,但我不能。使用无效参数

所以程序要求用户为3号的,然后询问自己想要加的,那么这些数字的百分比去一个void方法:

因此,它是这样的:

public static void main(String[] args) { 

     System.out.print("Number 1: "); 
     X1 = s.nextLong(); 
     System.out.print("Number 2: "); 
     W1 = s.nextLong(); 
     System.out.print("Number 3: "); 
     Z1 = s.nextLong(); 

     System.out.print("Percentage 1: "); 
     int a = s.nextInt(); 
     System.out.print("Percentage 2: "); 
     int b = s.nextInt(); 
     System.out.print("Percentage 3: "); 
     int c = s.nextInt(); 
     Number(a,b,c); 

} 

public static void Number(int a, int b, int c) 
{ 

    X1 = (long) (X1*(a/100 + 1)); 
    W1 = (long) (W1*(b/100 + 1)); 
    Z1 = (long) (Z1*(c/100 + 1)); 

} 

但如果我尝试输入数字不会改变的结果。

注:X1,W1和Z1全部用作静态长

而且在此先感谢。

+0

'public static void Number(int a,int b,int c){' - 这不是Javascript ..尝试Java –

+1

你怎样输出结果? –

+0

如何定义X1,W1和Z1? – Macondo2Seattle

回答

0

您正在整数参数除以整数100使用 - 你猜对它 - 整数算术结果在0任何值小于100。使用100.0强制浮点精度。

X1 = (long) (X1*(a/100.0 + 1.0)); 
... 
+0

谢谢它很有效! – TheUnknown

3

除非A,B,C> = 100,则表达式

a/100 

将为0。因此

something * (a/100 +1) 

something * 1 
0

除以在100.0你的电话号码数字方法。