【PAT 乙级(Basic Level)】分A+B
2015-06-05 09:58
267 查看
这题比较简单,写过一个简单的计算器的人应该都没问题,算是基础了。计算器中答案还需用String类型操作,因为有回退功能,这里可以直接用int操作。
直接上答案:
搜索
复制
直接上答案:
import java.util.Scanner; public class Main { private int cuculator(int number,int repeat){ int count=0,result=0; while(number!=0){ if(number%10==repeat){ count++; } number/=10; } if(count==0){ return 0; }else{ for(int i=0;i<count;i++){ result=result+repeat*(int)Math.pow(10, i); } return result; } } public static void main(String[] args) { Scanner s = new Scanner(System.in); int a=s.nextInt(); int da=s.nextInt(); int b=s.nextInt(); int db=s.nextInt(); int pa=0,pb=0; Main main=new Main(); pa=main.cuculator(a,da); pb=main.cuculator(b,db); System.out.println(pa+pb); } }
搜索
复制
相关文章推荐
- Index logic in MySQL& B- tree algorithm
- mysql数据库锁机制
- Java NIO系列教程(六) Selector
- 浅析人脸检测之Haar分类器方法:Haar特征、积分图、 AdaBoost 、级联
- shell基本命令
- Valid Number
- 匈牙利算法
- Open CASCADE Technology: IGES Support
- Android--app包中的fragment和v4包中的fragment的使用的区别
- Project Euler:Problem 42 Coded triangle numbers
- iOS 怎么让tableView滑动最底端
- php中的传值赋值,引用赋值
- CAS——傻瓜级入门
- 新书《iOS8 Swift编程指南》上架了
- matlab secant method
- TextFormat中的leading可控制行间距
- log4j 基础教程
- XE6 IntraWeb.v14.0.32安装及破解指南
- java代码性能优化
- CodeForces 492C Vanya and Exams