This is my program and everything is fine except the output needs to have the largest integer of x to be squared and cubed like this as an example:
System.out.println("\t\t\t"+"Squared Average:\t"+(Math.pow(Total,2));
System.out.println("\t\t\t"+"Cubed Average:\t"+(Math.pow(-Total,3));
The entire code is supposed to tell whether the number that is entered is positive or negative, the total of the positive and negative,the average of the positive and negative, and the largest value of the numbers entered squared and cubed using while loops and if statements with an exit
The thing is I don't know how to get the largest integer when it's x? I need some help here.:/
Also my exit isn't working for some reason even though I put enter 0 to exit.
Someone help a poor beginner?
import java.text.NumberFormat; import java.util.Scanner; public class Test { public static void main (String[] args) { double Total=0; double Average=0; double a=0; double x=1; int end=1; Scanner scan = new Scanner (System.in); while (x >= 0 && x <= 999999999) { if (x !=0) System.out.println("Enter a number"); x=scan.nextInt(); Total=Total+x; if (x == 0) { System.out.println("Cannot Accept Zeros, Try Again"); System.out.println("Please enter a number"); x=scan.nextInt(); if (x == 0) { System.out.println("Negative\t\t"+"Total:\t"+(Total/a)); System.out.println(); System.out.println("Positive\t\t"+"Total:\t"+(Total/a)); if (x == 0) end=0; if (x !=0) { a++; System.out.println("Positive"); System.out.println(x); System.out.println(); System.out.println("Negative"); System.out.println(-x); } } } }