-1
目前我有一个方法,要求用户输入字符串,但只输出前16个字符!该方法应该占用任意长度的字符串,然后在执行以下操作后以4x4块的形式输出字符:第一行保持不变。将第二行向左移一个位置,然后将第三行向左移两个位置。最后,将第四排三个位置移到左边。截至目前,它只会输出的第4×4块改变输入,可以采取任意长度的字符串,输出问题
而且我不知道我怎样才能改变方法,因此它不要求用户输入 我想它使用给定的字符串,如:
字符串text = shiftRows(“WVOGJTXQHUHXICWYYMGHTRKQHQPWKYVGLPYSPWGOINTOFOPMO”);
“WVOGJTXQHUHXICWYYMGHTRKQHQPWKYVGLPYSPWGOINTOFOPMO”是我想要使用的给定的加密字符串。但是,而不要求用户input..I不断收到错误和不正确outputs..please展示如何我可能会解决我用这
代码:
public class shiftRows {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
String[] input= new String[4];
String[] output= new String[4];
System.out.println("Enter a String");
String inputStr = sc.next();
for (int i = 0, n = 0; i < 4; i++, n+=4) {
input[i] = inputStr.substring(0+n, 4+n);
}
// -
output[0] = input[0];
for(int i=1; i<4; i++)
{
output[i] = Shift(input[i],i);
}
for(int i=0; i<4; i++)
{
System.out.println(output[i]);
}
}
public static String Shift(String str, int shiftNum)
{
char[] out = new char[4];
if(shiftNum==1)
{
out[0]=str.charAt(1);
out[1]=str.charAt(2);
out[2]=str.charAt(3);
out[3]=str.charAt(0);
}
if(shiftNum==2)
{
out[0]=str.charAt(2);
out[1]=str.charAt(3);
out[2]=str.charAt(0);
out[3]=str.charAt(1);
}
if(shiftNum==3)
{
out[0]=str.charAt(3);
out[1]=str.charAt(0);
out[2]=str.charAt(1);
out[3]=str.charAt(2);
}
return new String(out);
}
}
你是什么意思左移?你想要这种类型的输出测试HEYH IHOW AREY OU –
你应该停止在这里发布你的作业。 – Andreas