java 大数据次方运算
来源:互联网 发布:网络女主播电影华伊沫 编辑:程序博客网 时间:2024/05/20 08:42
/**引用网络文档*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Run
{
private static int radix = 307;
public static void main(String[] args) throws Exception
{
Run run = new Run();
int [] result = run.Power(radix);
logger.debug("++++ Caculate Result: +++++");
for(int i = result.length - 1; i >= 0; i--){
System.out.print(result[i]);
if(i % 50 ==0){
System.out.print(" ");
}
}
}
public static int input() {
String inline = null;
try {
BufferedReader inStream = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Please enter a power number for the radix 2: ");
inline = inStream.readLine();
int number = Integer.parseInt(inline);
return number;
} catch (NumberFormatException ex) {
System.out.println("Invalid!!");
return 0;
} catch (IOException e) {
System.out.println("Error!! ");
return 0;
}
}
int[] Power(int radix) throws Exception {
int[] result;
int n=input();
int size = (int) (n * Math.log10(radix)) + 1;
result = new int[size];
result[0] = 1;
if(n<0){
System.out.println("Sorry! Please enter a positive number!");
}
if (n == 0) {
result = new int[1];
result[0] = 1;
return result;
}
// get the result
for (int i = 0; i < n; i++) {
GetResult(result, radix);
}
return result;
}
void GetResult(int[] result, int n) {
int length = 0;
for (int i = result.length - 1; i >= 0; i--) {
if (result[i] > 0) {
length = i + 1; //get the highest bit
break;
}
}
for (int i = length - 1; i >= 0; i--) {
// calculate from the highest bit to the lowest
int temp = result[i] * n;
// get a carry
if (temp >= 10) {
// put a carry to a higher bit
result[i + 1] += temp / 10;
// check this bit weather need carry or not
CheckCarry(result, i + 1);
temp %= 10;
}
result[i] = temp;
}
}
void CheckCarry(int[] m, int index) {
if (m[index] >= 10) {
// put a carry to a higher bit
m[index + 1] += m[index] / 10;
// set the current bit
m[index] %= 10;
// check the next bit weather need carry or not
CheckCarry(m, index + 1);
}
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Run
{
private static int radix = 307;
public static void main(String[] args) throws Exception
{
Run run = new Run();
int [] result = run.Power(radix);
logger.debug("++++ Caculate Result: +++++");
for(int i = result.length - 1; i >= 0; i--){
System.out.print(result[i]);
if(i % 50 ==0){
System.out.print(" ");
}
}
}
public static int input() {
String inline = null;
try {
BufferedReader inStream = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Please enter a power number for the radix 2: ");
inline = inStream.readLine();
int number = Integer.parseInt(inline);
return number;
} catch (NumberFormatException ex) {
System.out.println("Invalid!!");
return 0;
} catch (IOException e) {
System.out.println("Error!! ");
return 0;
}
}
int[] Power(int radix) throws Exception {
int[] result;
int n=input();
int size = (int) (n * Math.log10(radix)) + 1;
result = new int[size];
result[0] = 1;
if(n<0){
System.out.println("Sorry! Please enter a positive number!");
}
if (n == 0) {
result = new int[1];
result[0] = 1;
return result;
}
// get the result
for (int i = 0; i < n; i++) {
GetResult(result, radix);
}
return result;
}
void GetResult(int[] result, int n) {
int length = 0;
for (int i = result.length - 1; i >= 0; i--) {
if (result[i] > 0) {
length = i + 1; //get the highest bit
break;
}
}
for (int i = length - 1; i >= 0; i--) {
// calculate from the highest bit to the lowest
int temp = result[i] * n;
// get a carry
if (temp >= 10) {
// put a carry to a higher bit
result[i + 1] += temp / 10;
// check this bit weather need carry or not
CheckCarry(result, i + 1);
temp %= 10;
}
result[i] = temp;
}
}
void CheckCarry(int[] m, int index) {
if (m[index] >= 10) {
// put a carry to a higher bit
m[index + 1] += m[index] / 10;
// set the current bit
m[index] %= 10;
// check the next bit weather need carry or not
CheckCarry(m, index + 1);
}
}
}
- java 大数据次方运算
- POJ1001幂次方的运算,大数据
- java大数据运算
- C++大数据运算{开n次方(二分法逐渐逼近求解),n次方,小数,符号,加减乘除模!}
- 大数据阶乘运算-java高精度运算
- BigInteger用法-Java大数据存储、运算
- Java实现大数据简单运算
- JAVA大数据运算系列之大整数相乘
- 九次方大数据十大平台助推数字经济发展
- 大数据的运算
- 大数据阶层运算
- 大数据运算
- 大数据运算
- 大数据运算
- 在JAVA中,使用BigDecimal进行大数据运算
- java语言进行大数据的乘法运算
- 大数据的加法运算Java代码实现
- Java笔试题——2的100次方,不用大数据类(Biginteger)来解答
- java中的String类型
- Java设置界面风格
- 以windows风格为例可以这们写:
- Spring配置中的bean引用其它bean的属性值
- FMDatabase的用法介绍
- java 大数据次方运算
- Java之RMI设计模式基本原理与示例
- Java常用的通信协议效率比较(转)
- Java面试题一 Java面试题122道(19道代码题)
- java.lang.OutOfMemoryError: PermGen space及其解决方法
- 如何将项目加入maven
- 查找数组中最大的2个数
- 结束多层循环
- ThreadLocal是否会引起内存溢出?