-5

I want to print the result the same way that i print the numbers that i use. for ex i print 1,2,3,4 2,3,4,5 but the pow remains the same 1024,1024,1024,1024.

public static void main(String[] args) {
    int d = 0, e = 0;
    double c = 0;
    for (int a = 1; a < 5; a++) {
        d = a;
        for (int b = 2; b < 6; b++) {
            c = java.lang.Math.pow(a, b);
        }
    }
    for (int a = 1, b = 2; a < 5; a++, b++) {
        d = a;
        e = b;
        System.out.println(d + " " + e + " " + c);
    }
}
sinclair
  • 2,812
  • 4
  • 24
  • 53
Koon
  • 1
  • 3
  • 2
    first please make the effort to format your code properly. this would better illustrate your problem. – Ousmane D. Oct 30 '17 at 23:11
  • public static void main(String[] args) { int d=0 ,e= 0; double c = 0; for (int a=1;a<5;a++) { d=a; for (int b=2;b<6;b++) { c=java.lang.Math.pow (a,b); } } for (int a=1,b=2;a<5;a++,b++) { d=a; e=b; System.out.println ( d+ " " +e +" " + c); } } } – Koon Oct 30 '17 at 23:13
  • @Koon This is worse. – luckydog32 Oct 30 '17 at 23:13
  • @luckydog32 The problem is that i cant print all the pow it print only the last part . – Koon Oct 30 '17 at 23:16
  • Hello and welcome on Stackoverflow. This questio is quite low-quality and probably your first question here and will most probably be closed soon. To prevent this from happening again in the future, please [take the tour](https://stackoverflow.com/tour), [read what is regraded as on-topic here](https://stackoverflow.com/help/on-topic) and [the information about how to ask a good question](https://stackoverflow.com/help/how-to-ask). – Turing85 Oct 30 '17 at 23:17
  • @Turing85 you are right but i thought that people here would resolve this blinded – Koon Oct 30 '17 at 23:21
  • 2
    @Koon so... you thought you could use other to do you (home)work for free? Nice attittude... – Turing85 Oct 30 '17 at 23:23
  • @Turing85 thnx for the editing,it is not a homework it is a way to understand printing of the for loop. – Koon Oct 30 '17 at 23:25
  • @Koon No one on here is going to be able to fix a problem if they don't know what it is. There's plenty of people on here that will be able to help you out with a programming question, as long as there is at least an effort to explain what the question is. – luckydog32 Oct 30 '17 at 23:25
  • @luckydog32 I want to find the power of a and b a starts from 1 till 4 b form 2 till 5 and i want to show the power of a and b like this 1 2 1 , 2 3 8 , 3 4 81,4 5 1024 but my program shows a and b and 1024 only not 1,8,81,1024 – Koon Oct 30 '17 at 23:30

2 Answers2

2

This should work, and is also more readable.(you really ought to indent code properly). Your problem is in the loop logic. What you are doing is probably possible with for loops, but i think a while loop with two conditionals would work nice.

int a = 1;
int b = 2;
double c = 0.0;

while (a < 5 && b < 6){
  c=java.lang.Math.pow (a,b);
  System.out.println ( a+ " " +b +" " + c); 
  b++;
  a++;
} 
0
public static void main(String[] args) {

    int d = 0, e = 0;
    double c = 0;
    for (int a = 1; a < 5; a++) {
        for (int b = 2; b < 6; b++) {

            c = java.lang.Math.pow(a, b);
            System.out.println(a + " " + b + " " + c);

        }

    }
}

If I understood your problem try something like this output should be ok