Search This Blog

Saturday, February 20, 2010

A simple Problem

Well, lets take a simple problem:
Input 3 numbers(integer) and find out the smallest one.
In how many simple ways can it be solved?
Dear all, now you keep posting the ways to solve it. Then I shall comment on them, possibly individually!
Remember: use bluej only.












Discussing Java application programming across the barrier of classroom for the young minds.

2 comments:

  1. class Check
    {
    public void disp(int a,int b,int c)
    {
    if((a<b)&&(a<c))
    System.out.println(a);
    if((c<b)&&(c<a))
    System.out.println(c);
    if((b<a)&&(b<c))
    System.out.println(b);
    }


    or

    public void disp(int a,int b, int c)
    {
    int s=a;
    if(b<s)
    s=b;
    if(c<s)
    s=c;
    System.out.println(s);
    }

    ReplyDelete
  2. Good. But why checking the 2nd and 3rd if with full condition in the first answer? We can still minimise it by eliminating the variables from conditions one by one.
    Think about it.

    ReplyDelete