CodeGym
CodeGym University
Learning
Course
Tasks
Surveys & Quizzes
Games
Help
Schedule
Community
Users
Forum
Chat
Articles
Success stories
Activity
Reviews
Subscriptions
Light theme
Question
  • Reviews
  • About us
Start
Start learning
Start learning now
  • All questions
ARIJIT MONDAL
Level 4
Kolkata
  • 11.04.2019
  • 870views
  • 7comments

Getting correct result , but verification fail as "The min method must return the minimum of the numbers a, b, and c."

Question about the task Minimum of three numbers
Java Syntax,  Level 2,  Lesson 8
Resolved

Write a function that computes the minimum of three numbers.

Hint:
You need to write the body of the existing min function.

Requirements:
  • The program should display text on the screen.
  • The min method should not display text on the screen.
  • The main method should call the min method four times.
  • The main method should display the result of the min method. Each time, on a new line.
  • The min method must return the minimum of the numbers a, b, and c.
package com.codegym.task.task02.task0216; /* Minimum of three numbers */ public class Solution { public static int min(int a, int b, int c) { //write your code here int min = 0; if(a <= b){ if (a <= c) min = a; } else if (b <= c){ min = b; } else { min = c; } return min; } public static void main(String[] args) throws Exception { System.out.println(min(1, 2, 3)); System.out.println(min(-1, -2, -3)); System.out.println(min(3, 5, 3)); System.out.println(min(5, 5, 10)); } }
0
Comments (7)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
ARIJIT MONDAL
Level 4 , Kolkata, India
11 April 2019, 18:26
I have tried this way, Not getting result for -1, -2, -3, it is showing result as -2 if(a <= b || a <= c) { return a; } else if(b <= c || b <= a) { return b; } else if(c <= a || c <= b ) { return c; } return 0;//write your code here }
0
Krystian
Level 6 , Warsaw, Poland
11 April 2019, 18:17
use "and" operator "||": if (a <= b || a <= c) it will help :) nesting ifs is confusing
0
Krystian
Level 6 , Warsaw, Poland
11 April 2019, 18:26
Dear God :D "&&"
0
ARIJIT MONDAL
Level 4 , Kolkata, India
11 April 2019, 18:33
Thanks, I fixed it, I was using II, as you mentioned I had to change it && and it works
0
Krystian
Level 6 , Warsaw, Poland
11 April 2019, 18:13
check result for 2, 2, 1
0
ARIJIT MONDAL
Level 4 , Kolkata, India
11 April 2019, 18:16
2,2,1 returning result as 0, can you please tell me how to fix my logic
0
Krystian
Level 6 , Warsaw, Poland
11 April 2019, 18:19
int min = 0; if(a <= b){ //true if (a <= c) //false min = a; //NO ELSE STATEMENT, REST ELSE IF ARE OMITTED } else if (b <= c){ min = b; } else { min = c; }
0
Learn
  • Registration
  • Java Course
  • Help with Tasks
  • Pricing
  • Game Projects
  • Java Syntax
Community
  • Users
  • Articles
  • Forum
  • Chat
  • Success Stories
  • Activity
  • Affiliate Program
Company
  • About us
  • Contacts
  • Reviews
  • Press Room
  • CodeGym for EDU
  • FAQ
  • Support
CodeGym CodeGym is an online course for learning Java programming from scratch. This course is a perfect way to master Java for beginners. It contains 1200+ tasks with instant verification and an essential scope of Java fundamentals theory. To help you succeed in education, we’ve implemented a set of motivational features: quizzes, coding projects, content about efficient learning and Java developer’s career.
Follow us
Interface language
Programmers Are Made, Not Born © 2023 CodeGym
MastercardVisa
Programmers Are Made, Not Born © 2023 CodeGym
This website uses cookies to provide you with personalized service. By using this website, you agree to our use of cookies. If you require more details, please read our Terms and Policy.