0

Logic Error

Please I need assistance..........Im trying to write a code that those the actions a² and a³..............but it's not giving me the right results... package com.javabook; public class msin { public static void main {String[] args) { System.out.println("a "+" a^2 "+" a^3"); for (int i=1; i<=6; i++) { System.out.println(i+" "+(i^2)+" "+(i^3)); } } }/* OUTPUT IS: a a^2 a^3 1 3 2 2 0 1 3 1 0 4 6 7 5 7 6 6 4 5 */

1st Jul 2018, 1:41 PM
Roff Bilex
Roff Bilex - avatar
3 ответов
+ 12
Just an advice if you're running your code in the Code Playground: Do not define or use packages ;) It isn't supported yet.
1st Jul 2018, 2:23 PM
Dev
Dev - avatar
+ 6
^ is bitwise Ex-OR operator, not the exponent, as Programanta ludanto mentioned use pow function or either for x² write x*x.
1st Jul 2018, 1:51 PM
Nikhil Dhama
Nikhil Dhama - avatar
+ 3
In Java, the operator "^" doesn't mean power. Instead, you need use "pow" function or write like "x*x". Math.pow(x, 2) x*x
1st Jul 2018, 1:44 PM
Disvolviĝo;
Disvolviĝo; - avatar