我是如何在Java中解决这个问题的 [英] How I Do This Problem In Java
问题描述
http://imageshack.com/a/img571/ 5209 / lzb1.png [ ^ ]
这是我的代码,但这段代码只给出了一个结果。我需要总结果
例如;对于N = 3
1 ^ 0 = 1
1 ^ 1 = 1
1 ^ 2 = 1
1 ^ 3 = 1
总结果= 4和
2 ^ 0 = 1
2 ^ 1 = 2
2 ^ 2 = 4
2 ^ 3 = 8
总结果= 15和
3 ^ 0 = 1 >
3 ^ 1 = 3
3 ^ 2 = 9
3 ^ 3 = 27
总结果= 40 .. ...
http://imageshack.com/a/img571/5209/lzb1.png[^]
and this my code but this code give just one by one result . i need total result
for example; for N =3
1^0=1
1^1=1
1^2=1
1^3=1
total result =4 and
2^0=1
2^1=2
2^2=4
2^3=8
total result =15 and
3^0=1
3^1=3
3^2=9
3^3=27
total result =40 .....
import java.awt.image.ConvolveOp;
import java.io.*;
import javax.swing.JOptionPane;
import java.util.Scanner;
public class main {
public static void main(String[] args){
double sonuc;
String N=JOptionPane.showInputDialog("Enter N");
int STPN= Integer.parseInt(N);
for(double Rho=1; Rho<=3;Rho++){
for(int i=0;i<=STPN;i++){
sonuc=Math.pow(Rho,i);
System.out.println("Sonuc : " + sonuc);
}
}
}
}
推荐答案
我用值3运行它,得到以下结果:
I run that with the value 3, and get the following results:
> run Test
Sonuc : 1.0
Sonuc : 1.0
Sonuc : 1.0
Sonuc : 1.0
Sonuc : 1.0
Sonuc : 2.0
Sonuc : 4.0
Sonuc : 8.0
Sonuc : 1.0
Sonuc : 3.0
Sonuc : 9.0
Sonuc : 27.0
请解释这部分是错误的以及原因。
Please explain which part of this is wrong and why.
for(int Rho=1; Rho<=STPN;Rho++){
int count=0;
for(int i=0;i<=STPN;i++){
count=(int) (count+Math.pow(Rho, i));
System.out.print(Rho+"^"+i+" = ");
System.out.println(count);
}
System.out.println("The Total Result Is = "+count);
}
用这段代码替换你的代码只需看看
Replace your code with this code it will be work just see
这篇关于我是如何在Java中解决这个问题的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!