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 4 of 4

Thread: Intro to Java

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Location
    MN, USA
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Intro to Java

    Hey so I'm taking a intro to java class and I'm told to (Computing the volume of a cylinder) Write a program that reads in the radius and length of a cylinder and computes volume using the following formulas:
    area = r*r*pi
    volume= area*length

    In the end the program is suppose to say "The area is...The volume is..."
    This is what I have so far but I am totally lost. Also let me know if it should use another way to show my code vs copy and paste. Please let me know what I am doing wrong.


    import java.util.Scanner;


    public class VolumeOfACylinder {

    public static void main(String[] args){

    // area = radius * radius * 3.14159

    Scanner scum = new Scanner(System.in);

    double radius = scum.nextDouble();

    System.out.println("Please enter the radius: ");

    double area;

    area = radius * radius * 3.14159;

    // volume = area * length

    Scanner solo = new Scanner(System.in);

    double area;

    double lenth = solo.nextDouble();

    System.out.println("Please enter the length: ");

    double volume;

    volume = area * length;

    System.out.println("The area is " + area + "and the volume is " + area * length );
    }
    }


  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: Intro to Java

    way to show my code vs copy and paste
    That way is good. One more thing to be done is wrap the code in code tags:

    [code=java]

    <YOUR CODE HERE>

    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Feb 2013
    Location
    MN, USA
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Intro to Java

    Quote Originally Posted by Norm View Post
    That way is good. One more thing to be done is wrap the code in code tags:

    [code=java]

    <YOUR CODE HERE>

    [/code]

    to get highlighting and preserve formatting.
    Okay still I still need help with the code idk why its not running.
    import java.util.Scanner;
     
     
    public class VolumeOfACylinder {
     
    public static void main(String[] args){
     
    // area = radius * radius * 3.14159 
     
    Scanner scum = new Scanner(System.in);
     
    double radius = scum.nextDouble();
     
    System.out.println("Please enter the radius: ");
     
    double area;
     
    area = radius * radius * 3.14159;
     
    //	volume = area * length
     
    Scanner solo = new Scanner(System.in);
     
    double area; 
     
    double lenth = solo.nextDouble();
     
    System.out.println("Please enter the length: ");
     
    double volume;
     
    volume = area * length; 
     
    System.out.println("The area is " + area + "and the volume is " + area * length );
    }
    }

  4. #4
    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: Intro to Java

    The formatting still needs work. The statements are not properly indented. Not all statements should start in the first column.

    why its not running.
    Please copy the full text of the error messages and paste it here.
    Otherwise explain what "not running" means.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. intro
    By vinai in forum Member Introductions
    Replies: 0
    Last Post: January 7th, 2013, 06:31 AM
  2. intro:
    By rajeev34 in forum Member Introductions
    Replies: 2
    Last Post: December 20th, 2012, 06:18 AM
  3. Intro to java assignment help
    By Rahiant in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 20th, 2012, 01:05 PM
  4. Intro to java hw assignment
    By coke32 in forum Java Theory & Questions
    Replies: 1
    Last Post: October 7th, 2011, 07:45 AM
  5. Intro
    By Thandaninkosi Moyo in forum Member Introductions
    Replies: 5
    Last Post: April 30th, 2010, 08:13 AM