huiwenshu.java

来自「包括角谷,色子,回文等矿大JAVA实验课留的作文」· Java 代码 · 共 51 行

JAVA
51
字号
package women;
import java.io.*;
public class Huiwenshu {
public static String readString()
{
	int ch;
	String r="";
	boolean done=false;
	while(!done)
	try{
		ch=System.in.read();
		if(ch<0||ch==0xd)
			done=true;
		else
			r=r+(char)ch;
	
	}catch(IOException e)
	{ System.out.println("error");done=true; };
	
	return r;
}
public static void main(String[] args)
{
	int num;
	boolean log=true;
	int index=0;
	int a[]=new int[10];
	String str;
	System.out.println("请输入一个整数值! ");	
	str=readString();
	num=Integer.parseInt(str);
	while(num!=0)
	{
		a[index]=num%10;
		num=num/10;
		index++;
	}
	for(int i=index-1,j=0;i>=0&&j<=i;i--,j++)
	{		
			if(a[i]!=a[j])
		    log=false; 
	}
        if(log)
	         System.out.print("是回文数! ");	
        else 
        	System.out.print("不是回文数! ");	
}
}
	

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?