计算 数的四种方法-2
2012-04-13 21:29
134 查看
package com.lesson21;
import java.util.Arrays;
public class Cal2 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
byte[] buf = new byte[1024];
int ret = 0;
int pos = 0;
int a = 0;
int b = 0;
String str = "";
int cout = 0;// 0 a 1 + 2 b
while (true) {
try {
ret = System.in.read();
} catch (Exception e) {
// TODO: handle exception
}
if(ret == 10) continue;
buf[pos++] = (byte) ret;
if (ret == 13) {
if (cout == 0) {
a = Integer.parseInt(new String(buf, 0, pos - 1));
pos = 0;
cout ++;
Arrays.fill(buf,(byte)0);
}else if(cout == 1){
str = new String(buf, 0, pos - 1);
pos = 0;
cout ++;
Arrays.fill(buf,(byte)0);
}else if(cout == 2){
b = Integer.parseInt(new String(buf, 0, pos - 1));
pos = 0;
cout = 0 ;
Arrays.fill(buf,(byte)0);
MyMath m = new MyMath(a, b,str);
int v = m.getValuse();
System.out.println("result is " + v);
}
}
}
}
}
import java.util.Arrays;
public class Cal2 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
byte[] buf = new byte[1024];
int ret = 0;
int pos = 0;
int a = 0;
int b = 0;
String str = "";
int cout = 0;// 0 a 1 + 2 b
while (true) {
try {
ret = System.in.read();
} catch (Exception e) {
// TODO: handle exception
}
if(ret == 10) continue;
buf[pos++] = (byte) ret;
if (ret == 13) {
if (cout == 0) {
a = Integer.parseInt(new String(buf, 0, pos - 1));
pos = 0;
cout ++;
Arrays.fill(buf,(byte)0);
}else if(cout == 1){
str = new String(buf, 0, pos - 1);
pos = 0;
cout ++;
Arrays.fill(buf,(byte)0);
}else if(cout == 2){
b = Integer.parseInt(new String(buf, 0, pos - 1));
pos = 0;
cout = 0 ;
Arrays.fill(buf,(byte)0);
MyMath m = new MyMath(a, b,str);
int v = m.getValuse();
System.out.println("result is " + v);
}
}
}
}
}
相关文章推荐
- C#自动计算字符串公式的四种方法
- C# 中使用 MD5 算法计算 hash (哈希)值的四种方法
- 【九天教您南方cass 9.1】 10 DTM土方计算的四种方法
- 四种方法实现UITableView的cell高度自动计算
- 计算 数的四种方法-1
- 关于计算最大子序列的四种方法
- C# 中使用 MD5 算法计算 hash (哈希)值的四种方法
- Python实现多项式计算的四种方法
- C# 中使用 MD5 算法计算 hash (哈希)值的四种方法
- 四种计算UIWebView高度的方法,总有一种适合你的需求
- ArcGIS应用——四种计算图斑面积的方法
- 各种信息熵(Information entropy)的计算方法
- python计算时间差的方法
- 动态计算控件高度和宽度的方法
- 面试题----僵尸进程的四种处理方法
- [转]关于日期天数计算的几种方法
- 在SQL Server数据库中批量导入数据的四种方法
- 使用BeginInvoke和EndInvoke进行异步调用的四种常用方法(转自小麻雀)
- java 遍历arrayList的四种方法
- 使用Spring Security3的四种方法概述