修改后的代码:
创新互联公司是一家专业从事成都网站制作、成都网站设计的网络公司。作为专业网站制作公司,创新互联公司依托的技术实力、以及多年的网站运营经验,为您提供专业的成都网站建设、全网整合营销推广及网站设计开发服务!
import java.util.Scanner;
public class test{
public static void main (String[] args){
Scanner input = new Scanner(System.in);
System.out.print("Please enter a positive integer");
int i = input.nextInt();
printNumber(i); //修改处
}
public static void printNumber (int i){
if (isPalindrome(i) isPrime(i)) {
System.out.println(i);
}
}
public static boolean isPalindrome(int i){
int palindrome = i;
int reverse =0;
while (palindrome !=0){
int remainder = palindrome % 10;
reverse = reverse *10 + remainder;
palindrome = palindrome/10;
}
if (i==reverse){
return true;
}
return false;
}
public static boolean isPrime (int i){
int counter = 2;
while(counteri){
if (i%counter ==0)
return false;
counter ++;
}
return true;
}
}
运行测试:
Please enter a positive integer101
101
Please enter a positive integer11
11
你的逻辑判断要写在while外面
public static boolean two(int b){
boolean flag = true;
int d=b;
int c = 0 ;
while(b 0){
c *= 10;
c += (b % 10);
b /= 10;
}
if(d != c ){
flag = false;
}
return flag;
}
}
public class $ {
public static void main(String[] args) {
for (int i = 1; i = 1000; i++) {
if (!check(i)) {
continue;
}
if (huiweishu(i)) {
System.out.println(i);
}
}
}
private static boolean check(int num) {
int sqrt = (int) Math.sqrt(num);
for (int j = 2; j sqrt + 1; j++) {
if (num % j == 0) {
return false;
}
}
return true;
}
private static boolean huiweishu(int i) {
int a;
if (i 99) {
a = i / 10;
} else {
a = i / 100;
}
return a == i % 10;
}
}
11
101
131
151
181
191
313
353
373
383
727
757
787
797
919
929