【输出幸运数程序】没人考?
发布于 2017-04-16 23:17 1618 次浏览 0 赞 来自 笔试面试  

import java.util.Scanner;


public class Main {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

while(sc.hasNextInt()){

int num1 = sc.nextInt();

int count = 0;

Xingyun t = new Xingyun();

for(int i = 0;i <= num1;i++){

if(t.duiChen(i)){

count++;

}

}

System.out.println(count);

}

sc.close();

}

}

class Xingyun{

public boolean duiChen(int num){

String str = String.valueOf(num);

int length = str.length();

for(int i = 0;i < length/2;i++){

if(str.charAt(i) != str.charAt(length-1-i)){

return false;

}

}

return true;

}

}


添加回复
回到顶部