i have to solve a task of two minimum numbers . but i am confused . please hint me out something related this question . thanks

Question:

Minimum of two numbers Write a program that reads two numbers from keyboard and displays to the screen the minimum of these numbers. */

import java.io.*;

asked 18 Mar '15, 16:51

Muhammad%20Hassan%20Durrani's gravatar image

Muhammad Has...
4311224
accept rate: 0%


this code works fine but it has not na pass testing . what it could be ??

import java.io.*;

public class Solution
{
    public static void main(String[] args) throws Exception
    {
        String input = null;
        String in = null;
        int num = 0;
        int number = 0;
        int m = 1;
        try 
        {
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
            input = bufferedReader.readLine();
            number = Integer.parseInt(input);
          in = bufferedReader.readLine();
          num = Integer.parseInt(in);

    if(number<num) m=number;
    else if(num<number) m=num;

        } 
            catch (NumberFormatException ex) 
            {
                System.out.println("Not a number !");
            }   
            catch (IOException e) 
            {
            e.printStackTrace();

    }

System.out.println(m);
    }
}
link

answered 18 Mar '15, 17:52

Muhammad%20Hassan%20Durrani's gravatar image

Muhammad Has...
4311224
accept rate: 0%

edited 19 Mar '15, 11:06

Elleonora%20Carry's gravatar image

Elleonora Carry ♦♦
275

if both first and second numbers equal to 4, what will be the minimum? In your code it is 1, compiler expects 4

(19 Mar '15, 11:09) Elleonora Carry ♦♦

According to the condition, the program should read two numbers from the keyboard and display the minimum number, there’s no mention of catching exceptions. So my guess is your code will probably pass the testing if you omit the “try… catch” part. Just using “if…else” statement worked for me.

link

answered 19 Mar '15, 08:07

tct1717's gravatar image

tct1717
111
accept rate: 0%

thanks mate :) i got it and got the correct answear .

link

answered 19 Mar '15, 17:28

Muhammad%20Hassan%20Durrani's gravatar image

Muhammad Has...
4311224
accept rate: 0%

import java.io.*;

public class Solution { public static void main(String[] args) throws Exception { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

    String num1 = reader.readLine();
    int a = Integer.parseInt(num1);
    String num2 = reader.readLine();
    int b = Integer.parseInt(num2);
          if (a < b)
          System.out.println(a+" is minimum");
          else
          System.out.println(b+" is minimum");
          //add your code here

}

} OUTPUT: ✓ The program is compiled without errors. ✗ The program runs correctly but it has not pass testing. This is program output during runtime:

34 is minimum

STILL NOT PASSING TEST.. WHY??????

link

answered 27 Mar '15, 16:50

Zain%20Mehar's gravatar image

Zain Mehar
13
accept rate: 0%

Zain.. looks good.. for your code to work you are depending on automatic type conversion since a is an int. you can try using the string variable num1 to pass the test. This outputs the same but it may satisfy the test. If you didn't try, use IDEA IDE with the same code as written and see if it accepts it.

link

answered 28 Mar '15, 19:13

Once%20the%20King%20of%20Andorra's gravatar image

Once the Kin...
676
accept rate: 11%

Zain.. looks good.. for your code to work you are depending on automatic type conversion since a is an int. you can try using the string variable num1 to pass the test. This outputs the same but it may satisfy the test. If you didn't try, use IDEA IDE with the same code as written and see if it accepts it.

link

answered 28 Mar '15, 19:13

Once%20the%20King%20of%20Andorra's gravatar image

Once the Kin...
676
accept rate: 11%

BufferedReader k=new BufferedReader(new InputStreamReader(System.in)); //System.out.println("enter first number"); String h=k.readLine(); int w=Integer.parseInt(h); // System.out.println("enter second number"); String q=k.readLine(); int e=Integer.parseInt(k.readLine()); if(w > e){ System.out.println(w);

    }
     else{
         System.out.println(e);
        }
        //add your code here
link

answered 22 Jul '15, 04:21

zeramal's gravatar image

zeramal
1
accept rate: 0%

import java.io.*;

public class Solution { public static void main(String[] args) throws Exception { int min = 0;

  //first input
    System.out.println("type  first no. :");
    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
    String sInput1 = bufferedReader.readLine();
    int nInput1 = Integer.parseInt(sInput1);

    //second input

    System.out.println("Type second nummber: ");
    String sInput2 = bufferedReader.readLine();
    int nInput2 = Integer.parseInt(sInput2);

    // logical part

    if (nInput1 < nInput2)
        min = nInput1;
    else
        min = nInput2;

    System.out.println(" min is  " + min);

}

}

link

answered 26 Aug '16, 10:41

VitaliKIV's gravatar image

VitaliKIV
111
accept rate: 0%

edited 26 Aug '16, 10:42

Just do not write explanation "min + "is minimum"" and it works.

  BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    String num1 = reader.readLine();
    int a = Integer.parseInt(num1);
    String num2 = reader.readLine();
    int b = Integer.parseInt(num2);
    if (a < b)
        System.out.println(a);
    else
        System.out.println(b);
link

answered 25 Dec '17, 11:20

Morkovkins%20Channel's gravatar image

Morkovkins C...
1
accept rate: 0%

 BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
    String s=reader.readLine();

    String n=reader.readLine();
     double ss=Double.parseDouble(s);
   double nn=Double.parseDouble(n);
    if (nn<ss) System.out.println(nn);
    else System.out.println(ss);

why it doesn't pass testing?

link

answered 26 Mar, 12:29

TheHex's gravatar image

TheHex
1
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×40
×36
×30

Asked: 18 Mar '15, 16:51

Seen: 3,013 times

Last updated: 26 Mar, 12:29