Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials:
 

Software Solutions and Services
 

 
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments
 
Comparing Two Numbers 
 

This is a very simple example of Java that teaches you the method of comparing two numbers and finding out the greater one.

 

Comparing Two Numbers

                         

This is a very simple example of Java that teaches you the method of comparing two numbers and finding out the greater one. First of all, name a class "Comparing" and take two numbers in this class. Here we have taken a=24 and b=25, now we have to find out whether a=b, a>b or b>a. To find out this apply if and else condition one by one. Now apply the condition "if (a=b)", if this satisfies then type that both are equal in the system class. If this doesn't satisfy, then check whether a>b by applying the "else if" condition and type the message "a is greater than b" in the system class. Again this doesn't satisfy then 'else' condition as shown in the example will show that b is greater than a. 

Now compile and run the program and you will find the desired output. If you are getting any error then check the whole program thoroughly and surely you will get correct result. By compiling and running this exact program, you will find that b is greater than a.

class  Comparing{
  public static void main(String[] args) {
    int a=24, b=25;
    if (a == b){
      System.out.println("Both are equal");
    }
    else if(a>b){
      System.out.println("a is greater than b");
    }
    else{
      System.out.println("b is greater than a");
    }
  }
}

Download this example:

                         

» View all related tutorials
Related Tags: c file array class list ui lists method get name using this oo root example where to exam drive store

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.

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:

can u help to write the program to compare more than 2 numbers

Posted by swapna.p.j on Friday, 12.19.08 @ 00:48am | #82951

Sir,

I am a beginner for java and i have just started working with programs. I planned to do the SCJP certification also soon.

Can you pls guide me to do some projects for the beginners.

Thanks
Madhu

Posted by Madhu on Tuesday, 10.7.08 @ 22:41pm | #80953

Dear Sir,
I have started learning Java since a month.
Please would you let me know of any small projects that I can start off.
It will be very helpful if you send me the list of projects to be done from a beginner to advance level.
Thank you in advance,
Anu

Posted by Anuradha Mundinamani on Saturday, 08.2.08 @ 15:43pm | #70530

dear sir,
is it necessary to give values to the identifier in java ?
and ther is no method to enter the value by d user?
plz sir reply me

Posted by nishu on Monday, 03.10.08 @ 09:59am | #52171

sir,IT IS VERY USEFUL TO ME TO LEARN JAVA.KINDLY SEND ME THE list of project in java that i can creat one advnce project.
THANKING YOU

Posted by ashvini on Wednesday, 02.27.08 @ 19:21pm | #50317

RESPECTED SIR,

IT IS VERY USEFUL TO ME TO LEARN JAVA.KINDLY SEND ME THE MCA QUESTION BANK FOR IST YEAR.IN MADURAI KAMARAJ UNIVERSITY.FOR 3 YEARS QUESTIONS.
THANKING YOU

Posted by E.DEEPA MERLIN on Friday, 01.18.08 @ 21:55pm | #45533

dear sir,
as a beginer,very important to my future,kindly send me (basics to standerd level )
notes.

Posted by manoj on Friday, 03.9.07 @ 18:35pm | #11246

In these programs don't we need import files?

Posted by Mits on Wednesday, 02.7.07 @ 15:52pm | #6595

sir tell me about(String args[]).

Posted by hardesh on Thursday, 02.1.07 @ 12:43pm | #5165

The above given example is very easy to understand and its helps us a lot to understand as i am learning java as a beginners

Posted by satinderkaurbal on Thursday, 12.14.06 @ 12:03pm | #1008

Training Courses
Tell A Friend
Your Friend Name
Website Designing Services
 
Web Designing Packages From $150!
 
Website Designing Company Web Hosting
 
Website Designing Quotation
 
Search Tutorials:

 

 
 

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 | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

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

Copyright © 2008. All rights reserved.