package com.codegym.task.task02.task0217;
/*
Minimum of four numbers
*/
public class Solution {
public static int min(int a, int b, int c, int d) {
//write your code here
int m1;
if(c<d)
m1=c;
else
m1=d;
if(m<m1)
m1=m;
return m1;
}
public static int min(int a, int b) {
//write your code here
int m;
if(a<b)
m=a;
else
m=b;
return m;
}
public static void main(String[] args) throws Exception {
System.out.println(min(-20, -10));
System.out.println(min(-20, -10, -30, -40));
System.out.println(min(-20, -10, -30, 40));
System.out.println(min(-40, -10, -30, 40));
}
}
i dont get it wats wrong in my code please someone help me
Resolved
Comments (10)
- Popular
- New
- Old
You must be signed in to leave a comment
Saheb Das
20 April 2019, 07:33
public static int min(int a, int b, int c, int d) {
//write your code here
int m1;
if(c<d)
m1=c;
else
m1=d;
int m = min(a, b);
if(m<m1)
m1=m;
return m1;
}
public static int min(int a, int b) {
//write your code here
int m;
if(a<b)
m=a;
else
m=b;
return m;
}
+2
Thope pavan
2 June 2019, 18:00
really oosum idea broh.plz be helpful like this for new learners like me
0
Harinath Reddy A
17 February 2019, 10:04
package com.codegym.task.task04.task0416;
/*
Crossing the road blindly
*/
import java.io.*;
public class Solution {
public static void main(String[] args) throws Exception {
//write your code here
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
String s = r.readLine();
double d = Double.parseDouble(s);
if((d%5>=0) && (d%5<3)){
System.out.println("Green");
}
else if((d%5>=3) && (d%5<4))
{
System.out.println("Yellow");
}
else
{
System.out.println("Red");
}
}
}
Please check this code please
0
Dexty
13 February 2019, 09:41
Your min(a,b) method is correct but your min(a,b,c,d) method is only comparing two numbers instead of the four, and also in that method you are to call the min(a,b) method
/*
Minimum of four numbers
*/
public class Solution {
public static int min(int a, int b, int c, int d) {
min(4,6);
int m;
int mm;
int m1;
int mm1;
if(a<b)
m=a;
else
m=b;
if(m<c)
mm=m;
else
mm=c;
if(mm<d)
mm1=mm;
else
mm1=d;
return mm1;
}
public static int min(int a, int b) {
//write your code here
int m;
if(a<b)
m=a;
else
m=b;
return m;
}
0
Harinath Reddy A
12 February 2019, 09:48
package com.codegym.task.task03.task0318;
/*
Plan to conquer the world
*/
import java.io.*;
public class Solution {
public static void main(String[] args) throws Exception {
//write your code here
BufferedReader reader= new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter your name");
String name = reader.readLine();
System.out.println("Enter your Age");
String Age = reader.readLine();
int Y= Integer.parseInt(Age);
System.out.println(name+" "+"will take over the world in"+" "+Y+" "+"years. Mwa-ha-ha")
}
}
Please Help me with this Sir!!!!
0
Fadi AlSaidi
10 February 2019, 01:50
I would recommend utilizing the method that compares two int and returns the minimum of the two.
So break the four int into two groups first.
As far as your code, the second if, if(m<m1), is comparing m variable which is declared outside of you method and in the second method. It will need to be declared, and giving a value inside your method.
I hope that helps. Hang in there, coding is about failing many times, and about practicing. Which is why Codegym is great.
0
Harinath Reddy A
10 February 2019, 20:26
thank you sir.
But how do I use the method of finding minimum of two number in the four numbers method.
0
Fadi AlSaidi
10 February 2019, 22:49
The min method with two parameters is the method I am talking about.
this task gave you min method to complete with the option to have min method with 2 parameters, and a min method with 4 parameters. the code for the min with two parameters works:-
public static int min(int a, int b) {
//write your code here
int m;
if(a<b)
m=a;
else
m=b;
return m;
}
for example if you wan to know what is the minimum of {5, 2, 8, 1}
take 5 and 2 first and return the minimum of those two then save it in a variable for later,
then compare 8 and 1, return the minimum of those two and save it in a variable. finally compare the two results of the above compression for a final minimum number.
is that what you were asking about? if not let me know
0
Harinath Reddy A
11 February 2019, 04:02
ok sir I get it!!
Thank You Very much.
0
Fadi AlSaidi
12 February 2019, 20:08
you are very welcome. don't forget to mark this question as solved if it helped you solve the issue
+1