Functions and Methods

Ads
 

Functions and Methods

Write a Java program to input the sides of a triangle. Pass the sides to a function decide(int x,int y,int z) which checks and prints whether the triangle is equilateral,isosceles or scalene.

View Answers

May 16, 2012 at 5:52 PM

The given code accepts the sides of triangle from the user. Pass the sides to a function decide(int x,int y,int z) which checks and prints whether the triangle is equilateral,isosceles or scalene.

import java.util.*;

class TypeOFTriangle 
{
    public static void decide(int side1,int side2,int side3){
        String type="";
            if(side1 == side2 && side2 == side3){
            type = "Equilateral";
            }
            else if(side1 == side2 && side2 != side3){
            type = "Isosceles";
            }
            else if(side1 == side3 && side2 != side3){
            type = "Isosceles";
            }
            else if(side1 != side3 && side2 == side3)
            type = "isosceles";

            else
            type = "Scalene";

            System.out.println(type);
    }
    public static void main(String[] args) 
    {
        Scanner input=new Scanner(System.in);
        System.out.print("Enter side 1: ");
        int side1=input.nextInt();

        System.out.print("Enter side 2: ");
        int side2=input.nextInt();

        System.out.print("Enter side 3: ");
        int side3=input.nextInt();

        decide(side1,side2,side3);

    }
}

Ads









Related Tutorials/Questions & Answers:
Functions and Methods
Functions and Methods  Write a Java program to input the sides of a triangle. Pass the sides to a function decide(int x,int y,int z) which checks and prints whether the triangle is equilateral,isosceles or scalene.   
Functions and Methods
Functions and Methods  (1) Write a program in java to input 10 numbers. Use a function to find and print the cube of each number. (2) Write a program in java to input day number. Use a function daysofweek(int dysno) to accept
Advertisements
methods
methods  PrintStream class has two formatting methods,what
methods
methods  PrintStream class has two formatting methods,what
methods
methods  PrintStream class has two formatting methods,what
Inbuild functions
Inbuild functions  List all the inbuild functions in java
static methods
static methods  why static methods cannot read or write the instance variables
static functions
2. Static Functions 3. Instance Variable  Static Variables Static... object. Static Methods Static method is the method which belongs to the class... call only other static methods and can not call a non-static method from it. 3
native methods
native methods  what is native methods in java?   A native method is a method that is implemented in a language other than Java. The Java native method is a great way to gain and merge the power of C or C++ programming
Even and odd functions in java
Even and odd functions in java  Even and odd functions in java  ... have two separate functions for checking either number is even or odd. We are passing number as argument in methods
functions strstr() and stristr().
functions strstr() and stristr().  What is the functionality of the functions strstr() and stristr
the functions unlink and unset
the functions unlink and unset  What is the difference between the functions unlink and unset
Various methods of httpservletresponse interface
Various methods of httpservletresponse interface  What are the various methods of httpservletresponse interface
ModuleNotFoundError: No module named 'functions'
ModuleNotFoundError: No module named 'functions'  Hi, My Python... 'functions' How to remove the ModuleNotFoundError: No module named 'functions' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'methods'
ModuleNotFoundError: No module named 'methods'  Hi, My Python... 'methods' How to remove the ModuleNotFoundError: No module named 'methods... to install padas library. You can install methods python with following command
GET and POST methods
GET and POST methods   What are the differences between GET and POST methods in form submitting, give the case where we can use GET and we can use POST methods
factory methods in java?
factory methods in java?  what are factory methods in java?   Hi Friend, Factory methods are static methods that return an instance of the native class like Pattern.compile(), Calendar.getInstance
Final Methods - Java Tutorials
methods The final method  can be declare as follows: public final String
Servlet Methods
Servlet Methods In this section we will read about the various methods... methods that are used to initialize a Servlet, handles the request received..., the Servlet methods are called life-cycle methods of Servlet. Following
c-language pointer functions
c-language pointer functions  what is the execution process of character pointer functions with example
abstract methods in java
abstract methods in java  what is abstract methods in java.give better examples for understanding   Hi Friend, Please visit the following link: http://www.roseindia.net/java/master-java/abstract-class.shtml Thanks
without using built-in functions
without using built-in functions  Hai sir... Please help me to solve this... Findout occurances of each string in every another string (built - in functions are not at all allowed) all, and, sand, falling wall and sand
looping through a list of methods
looping through a list of methods  I have a number of methods that do the almost same thing: public void setColorRed (int colorvalue); public...); Is there a way to place these methods in a list and then call each one from
Callback Methods
Callback Methods       Callbacks methods are the way of managing life cycle of an instance. Callback methods are generally used by containers. The methods are called at specific time
all c library functions
all c library functions  hi dear c coders, i need all c library functions with a detailed explanation. Who can give me usefull link? thanks beforehand!   Hi Friend, Please go through the following link: C Tutorials
What modifiers are allowed for methods in an Interface?
What modifiers are allowed for methods in an Interface?   Hi, What modifiers are allowed for methods in an Interface? thanks
Inverse of trigonometric functions in java.
Inverse of trigonometric functions in java.  How to get inverse of trigonometric functions in java?   public class InverseTrigno... Trigonometric functions are sin, cos and tan. Inverse of these functions
Hibernate Criteria Aggregate Functions Example
Hibernate Criteria Aggregate Functions Example  I need Hibernate Criteria Aggregate Functions Example program with source code, I want example of Hibernate Criteria Aggregate Functions? Can anyone share me the source code
ModuleNotFoundError: No module named 'architect-functions'
ModuleNotFoundError: No module named 'architect-functions'  Hi, My... named 'architect-functions' How to remove the ModuleNotFoundError: No module named 'architect-functions' error? Thanks   Hi
ModuleNotFoundError: No module named 'architect-functions'
ModuleNotFoundError: No module named 'architect-functions'  Hi, My... named 'architect-functions' How to remove the ModuleNotFoundError: No module named 'architect-functions' error? Thanks   Hi
ModuleNotFoundError: No module named 'architect-functions'
ModuleNotFoundError: No module named 'architect-functions'  Hi, My... named 'architect-functions' How to remove the ModuleNotFoundError: No module named 'architect-functions' error? Thanks   Hi

Ads