Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Beginner needs help with a program

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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?



    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);
     
    }
     
    }
    }
    }
    Last edited by MartinC; February 8th, 2012 at 08:22 AM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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.

  3. #3
    Junior Member
    Join Date
    Feb 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Beginner needs help with a program

    Quote Originally Posted by MartinC View Post
    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.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Beginner needs help with a program

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

Similar Threads

  1. [SOLVED] (Beginner) Program doesnt work
    By moneyman021 in forum What's Wrong With My Code?
    Replies: 10
    Last Post: January 15th, 2012, 04:28 AM
  2. Need Beginner Calculator Program help!
    By theJastro in forum What's Wrong With My Code?
    Replies: 18
    Last Post: December 17th, 2011, 07:30 PM
  3. Replies: 3
    Last Post: October 19th, 2011, 07:57 AM
  4. Beginner Java Program Help/ txt database search
    By JavaConfused in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: September 21st, 2011, 09:20 AM
  5. Issue with beginner program
    By suxen in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 5th, 2011, 08:55 AM