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

Thread: Can anyone try this for me!!!

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Can anyone try this for me!!!

    Write a program to read the height and width of a triangle from the user using a Scanner. The area of the triangle should be calculated and printed. All numbers should be read in as whole numbers (int).
    The area of a triangle is (base * height * 0.5).
    The output should look something like this:
    Please enter the height of the triangle
    17
    Please enter the base of the triangle
    19
    The area of the Triangle is 161.5

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Can anyone try this for me!!!

    Do you have any specific questions about your assignment?
    Please post your code and ask your questions.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Can anyone try this for me!!!

    Yeah missed the lecture on Scanner/user and cannot do it if you could put an example up i can try have a go at it

  4. #4
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Can anyone try this for me!!!

    Scanner s = new Scanner(System.in);

    int value = s.nextInt();

    Scanner (Java Platform SE 7 )

  5. #5
    Junior Member
    Join Date
    Apr 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Can anyone try this for me!!!

    import java.util.Scanner;

    public class TriangleExample {
    public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    System.out.println("Please enter the height of the triangle");
    System.out.println("Please enter the width of the triangle");
    int height = in.nextInt();
    int area = base * height;
    System.out.print("The area of the triangle is "+ area);
    }

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Can anyone try this for me!!!

    Does it work? Do you get errors? Please post the full text of any error messages.
    If it executes, does it print out the correct answer?
    If you don't understand my answer, don't ignore it, ask a question.

Tags for this Thread