如何完成我的凯撒密码? [英] How do I complete my Caesar Cipher?

查看:179
本文介绍了如何完成我的凯撒密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对如何完成我的项目感到困惑.我只需要将我的算法放在for循环下,但我迷路了.这是到目前为止的代码:

I am confused on how to finish my project. I just need to put my algorithm under my for loop but I am lost. Here is the code so far:

import java.util.Scanner;

public class Encryption {
	public Encryption () {
		//Empty constructor.
	}
	
	public void run() {
		
		boolean quit = false;
		Scanner input = new Scanner(System.in);
		
		while(quit == false)
		{
			
			System.out.println("Please enter a number between 1 and 26 or q to quit.\n");
			
			// Accept the user input
			String userKey = input.next();
			
			// Check to see if the user is quitting instead of entering in a new number
			if( userKey.charAt(0) == 'q' )
			{
				quit = true; 
				// Exits out of the loop
				System.out.println("Now exiting...");
			}
			
			else
			{
				// Convert user input into a number
				int userNum = Integer.parseInt(userKey);
				
				// Check if the number is within the valid range
				if( userNum > 0 || userNum < 27 )
				{
					System.out.println("Enter the message you wish to encrypt:\n");
					String userMessage = input.next();
					
					for(int i = 0; i < userMessage.length(); i++)
					{
						userMessage.charAt(i);
					}
					
				}
				
				else
				{
					System.out.println("Error: Please enter a number between 1 and 26 or q to quit.");
				}
				
			}
		}
		
		// Close the input stream
		input.close();
	}
}

推荐答案

因此,除了使它成为Caesar Cypher程序的位之外,您已经完成了全部操作?

您希望我们填补空白".

我们不做您的作业:这是有原因的.在这里,您可以考虑自己被告知的内容,并尝试理解它.也可以在那里帮助您的导师识别您的弱点,并将更多的注意力放在补救措施上.

自己尝试,您可能会发现它并不像您想的那样困难!
So you have done the whole thing, except the bit that makes it a Caesar Cypher program?

And you want us to "fill in the blanks".

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!


您与当前具有char和翻译参数.添加它们(处理溢出")以获得输出字符串的当前字符.
You are just a step (or, at least, few steps) away from the solution having the current char and the translation parameter. Add them (handling the ''overflow'') in order to obtain the current character of the output string.


这篇关于如何完成我的凯撒密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆