当int应答应该为0123时,IntelliJ输出不显示0 (Java)

当int应答应该为0123时,IntelliJ输出不显示0 (Java)

我是个CS学位的大一新生,学习Java。当我试图解释我的问题时,你会不会介意,因为我对Java/IDE还不太熟悉,而且还不太熟悉它是如何一起工作的?

首先,我的教授给了我们一个简单的任务,在询问用户时加密/解密四位数的值。(用于,例如。“输入要加密的四位整数”- 9835)

然后,代码将使用一些公式(不完全正确的加密),但它将把四位数转换成一个新的四位数数字。因此,对于这个例子,9835加密将是0265。

因此,当我的课程使用Netbeans作为首选IDE时,代码运行良好,9835的答案是0265。

但是今天,当我决定尝试IntelliJ Idea Community并复制完全相同的代码时,答案应该是0265,但是输出只显示265。不知怎么的,它没有显示0作为第一个数字。

请注意,我已经考虑过将加密的变量从整数转换为字符串-所以将显示0,但是我的教授说可以不进行任何转换(当使用Netbeans时)。

当在IntelliJ中运行代码时,我能做什么才能将确切的输出显示为Netbeans?(答覆为0265)

非常感谢,任何帮助/建议都是非常感谢的。

下面是我的代码供你参考。(这可能会让人困惑,但确实有效。)

代码语言:javascript运行复制 import java.util.Scanner;

class Encryption_Decryption

{

public static void main(String[] args)

{

Scanner input = new Scanner(System.in);

//Variables to store the inputs

int encrypted_value_input , decrypted_value_input;

//Variables for storing the individual digits.

int digit1_E , digit2_E , digit3_E , digit4_E; //Where digit1_E is the extreme left position and _E stands for Encrypted.

//Variables for storing the digits with the formula applied.

int a1_e , a2_e , a3_e , a4_e;

//Variables for storing the encrypted and decrypted values.

int encrypted_value , decrypted_value;

//Welcome Message

System.out.println("This is an Encryption and Decryption Application.");

System.out.println();

//Start of Encryption

System.out.print("Enter 4 digits to be Encrypted: ");

encrypted_value_input = input.nextInt();

digit1_E = (encrypted_value_input / 1000); //takes the first digit

digit2_E = ((encrypted_value_input / 100) % 10);

digit3_E = ((encrypted_value_input / 10) % 10);

digit4_E = (encrypted_value_input % 10);

//Encryption Formula

a1_e = (digit1_E + 7) % 10;

a2_e = (digit2_E + 7) % 10;

a3_e = (digit3_E + 7) % 10;

a4_e = (digit4_E + 7) % 10;

//Swapping the digits. For eg. 1234 is abcd. abcd needs to be swapped to become cdab.

int temp1 = a1_e;

a1_e = a3_e;

a3_e = temp1;

temp1 = a2_e;

a2_e = a4_e;

a4_e = temp1;

encrypted_value = a1_e * 1000 + a2_e * 100 + a3_e * 10 + a4_e;

System.out.println("The encrypted value is " + encrypted_value);

}

}

相关科技文章

支付宝扫红包后多久才能花钱?
beat365手机版官方

支付宝扫红包后多久才能花钱?

⌚ 08-30 👁️ 772
大青芒怎么切?详细图文教程教你轻松掌握切芒果技巧
beat365手机版官方

大青芒怎么切?详细图文教程教你轻松掌握切芒果技巧

⌚ 08-17 👁️ 6841
原始杀戮:灭绝
365平台网页版登录官网

原始杀戮:灭绝

⌚ 09-25 👁️ 9438
燃气表上的数字怎么看(燃气表读数如何解读)
365平台网页版登录官网

燃气表上的数字怎么看(燃气表读数如何解读)

⌚ 09-29 👁️ 5629
英政府曾考虑拒绝朝鲜参加66年世界杯
365平台网页版登录官网

英政府曾考虑拒绝朝鲜参加66年世界杯

⌚ 09-01 👁️ 2032
手把手教你制作电子签名:便捷高效的签名方式
beat365手机版官方

手把手教你制作电子签名:便捷高效的签名方式

⌚ 08-23 👁️ 7023

合作伙伴