gpt4 book ai didi

java - 为什么我在 Eclipse 中收到 "Selection does not contain a main type"消息?

转载 作者:行者123 更新时间:2023-11-29 06:44:03 25 4
gpt4 key购买 nike

import java.util.Scanner;

public class data {

public static int setoriginal() { //prompt user to input 4 digit number
int n = 0;
int l = 0;

do {
Scanner input = new Scanner(System.in);

System.out.println("Please enter a 4 digit number: ");
n = input.nextInt();

if (n >= 1000 && n <= 9999) {
break;
} else {
System.err.
printf("You did not enter 4 digits\n");
}

l = l + 1;
}
while (l < 3);

return n;
} //end method

public static int encrypt(int n) { //encrypt number inputted by user

int e1 = (((n / 1000) + 7) / 10);
int e2 = ((((n % 1000) / 100) + 7) / 10);
int e3 = ((((n % 100) / 10) + 7) / 10);
int e4 = ((((n % 10) / 1) + 7) / 10);

int e = e1 * 1000 + e2 * 100 + e3 * 10 + e4;

int firstPart = e % 100;
int lastPart = e / 100;

int result = firstPart * 100 + lastPart;

return result;
} //end method

public static int decrypt(int result) { //decrypt encrypted number

int d1 = (((result / 1000) - 7) * 10);
int d2 = ((((result % 1000) / 100) - 7) * 10);
int d3 = ((((result % 100) / 10) - 7) * 10);
int d4 = ((((result % 10) / 1) - 7) * 10);

int d = d1 * 1000 + d2 * 100 + d3 * 10 + d4;

int firstPart1 = d % 100;
int lastPart1 = d / 100;

int result1 = firstPart1 * 100 + lastPart1;

return result1;
} //end method

public static int decrypt1(int n) { //decrypted number inputted by user

int dd1 = (((n / 1000) - 7) * 10);
int dd2 = ((((n % 1000) / 100) - 7) * 10);
int dd3 = ((((n % 100) / 10) - 7) * 10);
int dd4 = ((((n % 10) / 1) - 7) * 10);

int dd = dd1 * 1000 + dd2 * 100 + dd3 * 10 + dd4;

int firstPart1 = dd % 100;
int lastPart1 = dd / 100;

int result1 = firstPart1 * 100 + lastPart1;

return result1;
} //end method

public static void display(int n, int result, int result1) { //output results
System.out.println("Originl number is: " + n);
System.out.println("\nEcrypted numebr is: " + result);
} //end method

public static void display1(int n, int result, int result1) { //output results
System.out.println("Originl number is: " + n);
System.out.println("\nDecrypted numebr is: " + result1);
} //end method

public static void getOriginal(int n) { //return original number
System.out.println("The original number is: \n" + n);
} //end method

public static void getEncrypt(int n, int result) { //return encrypted number
System.out.println("The encrypted number is: \n" + result);
} //end method

public static void main(String[]args, int result, int n, int result1) {
int m = 0;
Scanner input1 = new Scanner(System.in);

System.out.print("\nPlease choose from the following menu ");
System.out.print("\n1. Enter an original number");
System.out.print("\n2. Encrypt the number and print it");
System.out.print("\n3. Decrypt a number and print it");
System.out.print("\n4. Quit\n");
m = input1.nextInt();

while (m < 1 || m > 4) {
System.out.print("Error choose a number from 1-4");
m = input1.nextInt();
}

if (m == 1) {
setoriginal();
main(args, m, m, m);
}

else if (m == 2) {
if (setoriginal() == 0) {
System.out.
print
("Please enter an original number first");
main(args, m, m, m);
} else {
encrypt(n);
display(n, result, result1);
main(args, n, result, result1);
}
} else if (m == 3) {
if (encrypt(n) < 0) {
System.out.
print("Please encrypt your number first");
main(args, n, result, result1);
} else {
decrypt(n);
display1(n, result, result1);
main(args, n, result, result1);
}
} else if (m == 4) {
System.exit(0);

}

}
}

我在 eclipse 中没有遇到编译错误,但收到一条错误消息,指出“选择不包含主要类型”。任何想法可能是错的?另外,如果您看到任何其他错误,请告诉我。

最佳答案

你应该使用:

public static void main(String[] args)

代替:

public static void main(String[] args, int result, int n, int result1)

关于java - 为什么我在 Eclipse 中收到 "Selection does not contain a main type"消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8088239/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com