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
Re: Can anyone try this for me!!!
Do you have any specific questions about your assignment?
Please post your code and ask your questions.
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
Re: Can anyone try this for me!!!
Scanner s = new Scanner(System.in);
int value = s.nextInt();
Scanner (Java Platform SE 7 )
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);
}
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?