0
/**
 *
 * @author hamza
 */
public class Caesar_Chipher {


    // This is where I call my functions 
    public static void main(String[] args) {     
        userChoice();
    }



    //User chooses 1 or 2 to encrypt or decrypt
    public static void userChoice() {
        Scanner input = new Scanner(System.in); 
        System.out.print("Enter your choice, 1 = encrypt, 2 = decrypt: ");
        int userchoice; 
        userchoice = input.nextInt();
        if (userchoice == 1) {
            offsetNumber();
            message();
            System.out.println(plaintext + shift);
        }

        if (userchoice == 2) {
            offsetNumber();
            message();
            System.out.println(plaintext + shift);
        }

        else {
            userChoice();
        }
    }

    public static void offsetNumber() {
        Scanner offset = new Scanner(System.in);
        System.out.print("Enter your shift number: ");
        int shift;
        shift = offset.nextInt();
        if (shift < 27) {
            message();
        }
    }

    public static void message() {
        Scanner Message = new Scanner(System.in);
        System.out.print("Enter your message: ");
        String plaintext;
        plaintext = Message.next();
    }        
}

我的代码有什么问题?当有人加密时,我希望明文移动 n,而当有人解密时,我希望明文移动 -n。

4

1 回答 1

0

这还不是一个完整的答案,但评论不支持此代码示例的多行。

return 关键字将变量返回给方法的调用者。因此,在下面的示例returnMeAnInt()中,代码执行时将替换为 4。但是,它还有更多内容(尤其是实例和局部变量),因此堆栈溢出答案无法教您 java 的基础知识。去搜索教程 - 甚至更好:一本好书。

void main(String[] args) {
    int i = returnMeAnInt();
    System.out.println(i); // will print 4
}

int returnMeAnInt() {
    return 4;
}
于 2015-08-30T12:50:41.557 回答