Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML
 
 
Search All Tutorials
  

 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

Determining the largest number

                         

This example of Java programming will teach you the coding for determining the largest number amongst three. Here we have taken three integers as x = 500, y = 70 and z = 3000. After defining these three integers under the class "largernumber" apply "if" and "else" conditions that can help you in finding the largest value one by one. 

First check if "x>y". If this satisfies then check whether x>z or not. Again if this satisfies then write in the system class that "x is greater". Again the term "else" comes when "x" is not greater than "z". So check again, if "z" is greater than "y" or not. If this satisfies then type in the system class as "z is greater" otherwise (in the else condition) "y" is greater. Now check whether "y" is greater than "z" or not.

 If "x" is not greater than "y" as per the first condition, then the condition "else" comes and now you have to check if "y>z" or not. If this satisfies then the output comes as "y is greater".

Don't get confuse and analyze every condition one by one and follow this example.

Here is the code of program:

class largernumber{
  public static void main(String[] args) {
    int x=500, y=70, z=3000;
    if (x>y){
      if (x>z){
        System.out.println("x is greater");
      }
      else{
        if(z>y){
          System.out.println("z is greater")
        }
        else{
          System.out.println("y is greater");
        }
      }
    }
    else{
      if (y>z){
        System.out.println("y is greater");
      }
    }
  }
}

Download this example.

                         

Facing Programming Problem?
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

11 comments so far (post your own) View All Comments Latest 10 Comments:

This is another type of example for finding the largest number.
class velu1
{
public static void main(String args[])
{
int a=3,b=1,c=4;
if (a>b && a>c)
{
System.out.println("a is greatest");
}
else
if (b>c && b>a)
{
System.out.println("b is greatest");
}
else
if (c>a && c>b)
{
System.out.println("c is greatest");
}
}
}

Posted by veluswamy on Saturday, 08.23.08 @ 22:41pm | #74656

For example,
If x = 2, y = 200 and z = 400
this program does not produce the output as it never compares y and z separately.

I think another line of code should be added as in:
class LargerNumber{
public static void main(String[] args) {
int x=2, y=70, z=3000;
if (x>y){
if (x>z){
System.out.println("x is greater");
}
else{
if(z>y){
System.out.println("z is greater");
}
else{
System.out.println("y is greater");
}
}
}
else if (y>z){
System.out.println("y is greater");
}

else
System.out.println("z is greater");

}
}

Posted by Anuradha Mundinamani on Saturday, 08.2.08 @ 16:46pm | #70536

in above this program we are initiating no to variables other than this declare only variables and compare and they should read the values at compilation time ao simply what is the syntax for input of charater or nos.

Posted by lavanya on Monday, 04.28.08 @ 22:27pm | #58083

thanks a lot

Posted by pankaj jha on Thursday, 02.7.08 @ 14:40pm | #47504

class greaternumber
{
public static void main(String[] args)
{
int x=100,y=200,z=12;
if (x>y && y>z)
{
System.out.println("x is the Greater number");
}
else if(z>x && z>y)
{
System.out.println ("Z is the larget number");
}
else
{
System.out.println("Y is the larger number");
}
}
}

Posted by mangalamalatkar on Wednesday, 04.25.07 @ 16:40pm | #14917

BEING FRIENDLY AM HAPPY THAT NOW I CAN DO JUST A THING WITH JAVA.IT TAKES ME MORE THAN 3 WEEKS NOW TRYING TO UNDERSTAND WHAT WAS BEING TOUGHT BUT TODAY &I MEAN THIS DAY AM CAPABLE....KEEP ON HELPING US..THANX A LOT

Posted by l'ness on Thursday, 04.12.07 @ 00:05am | #13911

If the task is display the largest number among 100 integers, then what would be the solution, should we folow IF condition or Loop or something else please send the coding or the logic if anyone could solve this?

Posted by Shajib on Thursday, 03.15.07 @ 23:02pm | #11839

please explain me about (string[] args) in the main method

Posted by pranitha on Tuesday, 02.20.07 @ 04:52am | #8421

Thank you very much for setting up the example and sharing the code. I feel there may be some redundancy after the first else statement.
Best Regards,
Kim

Posted by Kim Tran on Thursday, 02.1.07 @ 16:04pm | #5204

ya this example is too good , but if it is some what diffecult that will be better ok eny way thanks for this examples

Posted by sharath pawar on Tuesday, 01.23.07 @ 16:46pm | #4143

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.