2014-10-27 51 views
-1
import java.util.*;  
public class LNFI_LNFI_program2 {  
static int globnum;  
static Scanner console = new Scanner (System.in);  
public static void main(String[] args) {  
    int globnum2 = globnum;  
    getnum();  
    encrypt(globnum2);  
} 

// encrypt methods  
public static int encrypt(int num)  
{  
    num = globnum;  
    int firstDigit, secondDigit, thirdDigit, fourthDigit, temp;  
    firstDigit = num/1000 % 10;  
     secondDigit = num/100 % 10;  
     thirdDigit = num/10 % 10;  
     fourthDigit = num % 10;  
     firstDigit = (firstDigit + 7) % 10;  
     secondDigit = (secondDigit + 7) % 10;  
     thirdDigit = (thirdDigit + 7) %10; 
     fourthDigit = (fourthDigit + 7) % 10;  
     temp = firstDigit;  
     firstDigit = thirdDigit;  
     thirdDigit = temp;  
     temp = secondDigit;  
     secondDigit = fourthDigit;  
     fourthDigit = temp;    
     System.out.printf("the encrypted number is %d%d%d%d\n",  
       firstDigit, secondDigit, thirdDigit, fourthDigit);    
    return num;  
}  

// getnum  
public static int getnum()  
    {  
     int numentered;   
     System.out.println("Please enter a number");  
     numentered = console.nextInt();   
     return numentered;  
    }  
} 

这是返回值,我收到我收到了错误的整数。而不是7777我应该得到0189

请输入号码
加密的数字是7777

回答

0

你覆盖传递给您的encrypt方法的号码:

num = globnum;

globnum默认为0。

当然,即使您没有覆盖它,也会将相同的0传递给encrypt方法。

您从不使用getnum()方法的输出。

因此0进行加密,以7777

更改你主要到:

public static void main(String[] args) {  
    encrypt(getnum());  
} 

和除去的encrypt的第一行。

相关问题