# Beginner needs help with a program

• February 7th, 2012, 11:33 PM
MartinC
Beginner needs help with a program
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? :)

Code :

```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);   }   } } }```
• February 8th, 2012, 06:22 AM
Norm
Re: Beginner needs help with a program
You should format your code with proper indentation (3-4 spaces) within each pair of {}s. Your code is very hard to read without the indentation.
• February 8th, 2012, 07:23 AM
MartinC
Re: Beginner needs help with a program
Ok, I tried to make it easier to read, it's just that I'm in a hurry at the moment.
• February 8th, 2012, 07:41 AM
KevinWorkman
Re: Beginner needs help with a program
Quote:

Originally Posted by MartinC
Ok, I tried to make it easier to read, it's just that I'm in a hurry at the moment.

And we're all doing this for free, in our spare time. You're making it harder for us to read your code just because you don't feel like taking the 30 seconds to format it, which is pretty rude. And it's going to decrease your chances of getting help as nobody wants to read unformatted code, so if you're in a hurry, your best bet is to format your code anyway.
• February 8th, 2012, 08:51 AM
Norm
Re: Beginner needs help with a program
Quote:

I'm in a hurry at the moment.
That's no problem, we can wait until you get a chance to fix it.