Ⅰ java怎麼用鍵盤輸入的數據進行計算
出現這樣的問題的主要原因是你不十分清楚面向對象的開發的意義。
java中,Scanner是一個類,他用來處理從輸入流中輸入的數據,將它轉換為目標數據,因此它可以根據需要多次讀取數據,只要輸入流中有數據。也就是說:他不是輸入的內容,而是為你提供了一個獲取輸入的工具,打個比方就相當於你的鍵盤了。
建議你學習以下OOP的思想。
下面是我給你修改的:
i nt c;
S canner s = new Scanner(System.in);
System.out.println("計算a+b和a*b的值。");
System.out.println("先輸入a的值並回車。");
int a = s.nextInt();
System.out.println("再輸入b的值並回車。");
int b = s.nextInt();
c = a + b;
System.out.println("good");
System
Ⅱ java語言中的計算變數的值
int
a=4;
計算下面兩個表達式的值:
(a++)
+=
a;
分析一下:首先說一下,a++,是先把a
的值提取出來運算後再+1;所以,這個程式就
分解成(a++)=4+4;把
8賦予a;然後a++,所以值為9;
(++a)
+=
(a++);
如果:是上面那個方程同一個方法裡面的話,那麼a之前的內存空間並沒有被回收;
所以保留原有的數值,那麼,繼續(++a)先執行;此時
,a=9;a=9+9,就是a=18;結束後別忘記之前還有a++每加上去;結果自然是19賦予a;
如果,2個方程不在同一個方法,那麼,2個a的值就不關聯;a+1=5;
接著a=5+5就等於10
;別忘記,還有個1;所以就是11;
講的夠詳細么?
Ⅲ java中如何對較大的數字進行計算
不管是不是用JAVA,其實方法都一樣,利用數組比如說長度為一千的數字,可以這個 int[] number = new int[1000];相加的思路是,首先兩個數組的長度必須是一致,位數不同的話,前面補0,內存有點浪費,但是計算起來比較方便。然後讓它們從0到最高位,每位進行相加並保存相應的位置上。最後一步是從0開始判斷有沒有大於10的數字,如果有就向前面進位(前一個加1,當前位減10),這樣就可以。如果是相減,其實思路還是一樣的,每位先相減,再判斷是否有小於0的,如果有則向前面一位借1(前一位減1,當前位加10)如果是相乘,和上面一樣,不過要注意的是進位的時候,不止進一位,比如5*6,就要向前進3位了(前一位加3,當前位減30)除就比較麻煩點,要涉及到精確度問題,得看實際需要 輸出就更容易了,直接for循環數組 特別要注意的是,如果最高位有進位的時候,這個是比較容易出錯的地方 思路在上面,如果實現不了請留言
Ⅳ java中如何有自己輸入數字後根據輸入數字計算啊
輸入操作是Scanner sc=new Scanner(System.in);然後輸入你的值,並且用一個變數接收這個輸入值,如果你輸入的是整數,那麼就int i=sc.nextInt(),如果你輸入的是浮點型,那就用一個浮點型變數接收輸入值,float i=sc.nextFloat(),然後那你的這個變數參與計算,如果你要一次輸入多個數字的話,可以用一個集合或數組來接收,如float[] arr=new Float[10],然後從鍵盤上輸入10個值,按照你輸入的先後順序依次存入到arr數組中,不過數組數值是要在循環中接收的。給你個例子代碼吧:
import java.util.Scanner;
public class test{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
Float[] arr=new Float[10];
//獲取從鍵盤上輸入的數值
for(int i=0;i<arr.length;i++){
arr[i]=sc.nextFloat();
}
//進行計算
float a=arr[0]+arr[1];
system.out.println(a);
}
}
Ⅳ JAVA有哪些適合進行數值計算,數據分析/機器學習的庫
直接搜關鍵詞:numerical computations in java
1、https //en wikipedia org/wiki/Java_programming_language
Apache Commons, is an open-source for creating reusable Java components. It has numerical packages for linear algebra and non-linear optimization.
ND4J is an open-source library that supports n-dimensional (ND) arrays, similar to NumPy. It runs on distributed GPUs or CPUs cross-platform. It supports thedeep learning library Deeplearning4j.
Colt provides a set of Open Source Libraries for High Performance Scientific and Technical Computing.
Efficient Java Matrix Library (EJML) is an open-source linear algebra library for manipulating dense matrices.
JAMA, a numerical linear algebra toolkit for the Java programming language. No active development has taken place since 2005, but it still one of the more popular linear algebra packages in Java.
Jblas: Linear Algebra for Java, a linear algebra library which is an easy to use wrapper around BLAS and LAPACK.
Parallel Colt is an open source library for scientific computing. A parallel extension of Colt.
DataMelt, an open-source Java libraries for numerical calculations, data I/O and visualization of scientific results. Used together with Jython.
JMSL Numerical Libraries, is a comprehensive set of mathematical, statistical, data mining, financial and 2D/3D charting classes.
Matrix Toolkit Java is a linear algebra library based on BLAS and LAPACK.
OjAlgo is an open source Java library for mathematics, linear algebra and optimisation.
exp4j is a small Java library for evaluation of mathematical expressions.
la4j is a tiny Java library and it provides linear algebra primitives and algorithms.
Universal Java Matrix Package UJM is a Java library which provides implementations for sparse and dense matrices, as well as linear algebra calculations such as matrix decomposition, inverse, multiply, mean, correlation, standard deviation, etc.
Java Matrix Library A thoughtfully designed Java library for dealing with Matrices ( Matrix Theory ). Simple, Intuitive and Flexible. The library revolves around a Matrix interface. Operations are thoughtfully distributed. Not guilty of exposing all-in-one Matrix class.
JDistLib Java Statistical Distribution Library is a Java package that provides routines for various statistical distributions. A manual translation of distributions provided by R statistical package.
SuanShu by Numerical Method Inc. is a large collection of numerical algorithms including linear algebra, (advanced) optimization, interpolation, Markov model, principal component analysis, time series analysis, hypothesis testing, regressions, statistics, ordinary and partial differential equation solvers.
2、Java Numerics: Main
Apfloat is a arbitrary precision floating-point arithmetic package.
ArciMath BigDecimal is an extension of java.math.BigDecimal based on IBM's Java Specification Request.
Colt is a free Java toolkit containing data structures and utilities intended for high performance computing.
Commons-Math The Jakarta Mathematics Library is is a library of lightweight, self-contained mathematics and statistics components addressing the most common problems not available in the Java programming language.
Drej, an open-source Java library for linear and non-linear least-squares regression and regularized least-squares classification.
A translation of the ELEFUNT Elementary Functions Testing Package has been ported to Java. The collection also contains extensions to java.lang.Math and new classes for numeric output formatting.
IBM's AlphaWorks contains several tools of interest, including
library of correctly rounded elementary functions intended for use with Java.
Ninja, a set of classes for numerically intensive Java, including complex, multidimensional arrays, and the BLAS. (RETIRED)
Java Numerical Toolkit (JNT)
Special functions including Bessel functions, Chebyshev series.
Zero root finder
Random Number generators for uniform and normal sequences of floating point numbers and long integers.
Java Ultimate Math Package, a framework for arbitrary precision computations.
The Java3D effort proced a matrix package for use in graphics.
JMSL, a collection of mathematical, statistical and charting classes, written in 100% Java, marketed by Visual Numeric, Inc. Includes linear algebra, zero finding, splines, ordinary differential equations, linear programming, nonlinear optimization, FFTs, special functions, regression, ANOVA, ARMA, Kalman filters.
JLargeArrays, a pure Java library of one-dimensional numeric arrays that can store up to 2^63 elements.
JSci, a set of Java packages for linear algebra, statistics, wavelets. Includes chart/graph components and a partial MathML DOM implementation.
jScience contains packages for numerical linear algebra, for computing with units (e.g., kg., sec.), and other utility operations.
Jspline+ is a spline approximation library for Java developed at the Institute of Computational Mathematics and Mathematical Geophysics (RAS) in Novosibirsk. It contains classes for univariate and multivariate spline approximation on scattered meshes, as well as core matrix and linear system solution classes.
JTransforms, The first open source, multithreaded FFT library in pure Java.
Koalog Constraint Solver is a commercial Java library for solving combinatorial optimization problems using Constraint Programming or Local Search.
Least Squares Software markets the jCrunch[tm] class libraries for numerical computing.
mpjava is a Java implementation of David Bailey's Fortran-based multiprecision package. The package performs multi precision floating point arithmetic with arbitrary precision level. It takes advantage of Java's inheritance facility to provide smooth transition from primitive arithmetic types.
netlib has a small collection of Java numerical classes.
A Numerical Library in Java for Scientists and Engineers, a book published by CRC Press, contains a CD-ROM with translation into Java of the library NUMAL (NUMerical proceres in Algol 60).
Ⅵ 關於JAVA表格里數值計算的問題
public Object getValueAt(int row,
int column)返回 row 和 column 位置的單元格值。
註:列是以表視圖的顯示順序,而不是以 TableModel 的列順序指定的。這是一項重要的區別,因為在用戶重新安排表中的列時,視圖中給定索引處的列將更改。同時用戶的操作不會影響模型的列順序。
參數:
row - 其值要被查詢的行
column - 其值要被查詢的列
返回:
指定單元格處的 Object
再把對象換成數字就好咯
Ⅶ 請大神,幫忙一個java數值計算2次方的源代碼 看哪裡出錯 java.lang.Math.pow(a
請按我這樣寫:
int a=3,b=2;
double c=Math.pow(a,b);
變數要先賦值、後使用,否則會產生不可預料的錯誤;另外,通常情況下,計算結果要保存起來,存放於另一個變數中,方便後續使用。
Ⅷ JAVA有哪些適合進行數值計算,數據分析/機器學習的庫
Apache Commons, is an open-source for creating reusable Java components. It has numerical packages for linear algebra and non-linear optimization.
ND4J is an open-source library that supports n-dimensional (ND) arrays, similar to NumPy. It runs on distributed GPUs or CPUs cross-platform. It supports thedeep learning library Deeplearning4j.
Colt provides a set of Open Source Libraries for High Performance Scientific and Technical Computing.
Efficient Java Matrix Library (EJML) is an open-source linear algebra library for manipulating dense matrices.
JAMA, a numerical linear algebra toolkit for the Java programming language. No active development has taken place since 2005, but it still one of the more popular linear algebra packages in Java.
Jblas: Linear Algebra for Java, a linear algebra library which is an easy to use wrapper around BLAS and LAPACK.
Parallel Colt is an open source library for scientific computing. A parallel extension of Colt.
DataMelt, an open-source Java libraries for numerical calculations, data I/O and visualization of scientific results. Used together with Jython.
JMSL Numerical Libraries, is a comprehensive set of mathematical, statistical, data mining, financial and 2D/3D charting classes.
Matrix Toolkit Java is a linear algebra library based on BLAS and LAPACK.
OjAlgo is an open source Java library for mathematics, linear algebra and optimisation.
exp4j is a small Java library for evaluation of mathematical expressions.
la4j is a tiny Java library and it provides linear algebra primitives and algorithms.
Universal Java Matrix Package UJM is a Java library which provides implementations for sparse and dense matrices, as well as linear algebra calculations such as matrix decomposition, inverse, multiply, mean, correlation, standard deviation, etc.
Java Matrix Library A thoughtfully designed Java library for dealing with Matrices ( Matrix Theory ). Simple, Intuitive and Flexible. The library revolves around a Matrix interface. Operations are thoughtfully distributed. Not guilty of exposing all-in-one Matrix class.
JDistLib Java Statistical Distribution Library is a Java package that provides routines for various statistical distributions. A manual translation of distributions provided by R statistical package.
SuanShu by Numerical Method Inc. is a large collection of numerical algorithms including linear algebra, (advanced) optimization, interpolation, Markov model, principal component analysis, time series analysis, hypothesis testing, regressions, statistics, ordinary and partial differential equation solvers.
2、Java Numerics: Main
Apfloat is a arbitrary precision floating-point arithmetic package.
ArciMath BigDecimal is an extension of java.math.BigDecimal based on IBM's Java Specification Request.
Colt is a free Java toolkit containing data structures and utilities intended for high performance computing.
Commons-Math The Jakarta Mathematics Library is is a library of lightweight, self-contained mathematics and statistics components addressing the most common problems not available in the Java programming language.
Drej, an open-source Java library for linear and non-linear least-squares regression and regularized least-squares classification.
A translation of the ELEFUNT Elementary Functions Testing Package has been ported to Java. The collection also contains extensions to java.lang.Math and new classes for numeric output formatting.
IBM's AlphaWorks contains several tools of interest, including
library of correctly rounded elementary functions intended for use with Java.
Ninja, a set of classes for numerically intensive Java, including complex, multidimensional arrays, and the BLAS. (RETIRED)
Java Numerical Toolkit (JNT)
Special functions including Bessel functions, Chebyshev series.
Zero root finder
Random Number generators for uniform and normal sequences of floating point numbers and long integers.
Java Ultimate Math Package, a framework for arbitrary precision computations.
The Java3D effort proced a matrix package for use in graphics.
JMSL, a collection of mathematical, statistical and charting classes, written in 100% Java, marketed by Visual Numeric, Inc. Includes linear algebra, zero finding, splines, ordinary differential equations, linear programming, nonlinear optimization, FFTs, special functions, regression, ANOVA, ARMA, Kalman filters.
JLargeArrays, a pure Java library of one-dimensional numeric arrays that can store up to 2^63 elements.
JSci, a set of Java packages for linear algebra, statistics, wavelets. Includes chart/graph components and a partial MathML DOM implementation.
jScience contains packages for numerical linear algebra, for computing with units (e.g., kg., sec.), and other utility operations.
Jspline+ is a spline approximation library for Java developed at the Institute of Computational Mathematics and Mathematical Geophysics (RAS) in Novosibirsk. It contains classes for univariate and multivariate spline approximation on scattered meshes, as well as core matrix and linear system solution classes.
JTransforms, The first open source, multithreaded FFT library in pure Java.
Koalog Constraint Solver is a commercial Java library for solving combinatorial optimization problems using Constraint Programming or Local Search.
Least Squares Software markets the jCrunch[tm] class libraries for numerical computing.
mpjava is a Java implementation of David Bailey's Fortran-based multiprecision package. The package performs multi precision floating point arithmetic with arbitrary precision level. It takes advantage of Java's inheritance facility to provide smooth transition from primitive arithmetic types.
netlib has a small collection of Java numerical classes.
A Numerical Library in Java for Scientists and Engineers, a book published by CRC Press, contains a CD-ROM with translation into Java of the library NUMAL (NUMerical proceres in Algol 60).
Ⅸ java里自己建立的包里能進行數值計算嗎
你的數組信息存放在w[]中,而w[]是一個RIC構造函數中的局部變數,所以w[]的作用域是RIC構造函數,當RIC對象創建完成之後,作用域消失,此時w[]對象引用也會消失,所以在外部你不可能獲取該信息。如果你希望獲取這個數組的值信息,可以將w[]定義成RIC的一個變數,並對外提供一個獲取該變數的方法,如下:
public class RIC{
private double w[];
public RIC(int d,int a,int b,double c){
//其他操作保持不變
w[]=new double[100];
for(int i=0;i<ii;i++){
w[i]=(Math.exp((- Math.pow((2*Math.PI*f/GAM),2))*Math.pow(t,2)))*Math.cos(2*Math.PI*f*t);
}
}
public double[] getW(){
return w;
}
}
這樣你就可以在主程序中獲取到數組的信息了。
其實這種方式不是很推薦,因為程序設計時,不提倡在構造函數中引入復雜的邏輯,你計算的過程其實可以放到一個獨立的方法中。