CodeGym
Promotie
Leren
Cursussen
Opdrachten
Enquêtes & Quizzen
Spellen
Hulp
Agenda
Community
Gebruikers
Forum
Chat
Artikelen
Succesverhalen
Activiteit
Beoordelingen
Abonnementen
Licht thema
Vraag
  • Beoordelingen
  • Over ons
Start
Begin met leren
Begin nu met leren
  • Alle vragen
CodeGym/Hulp bij Java-taken/In row 11, what does it mean? and the :
ah.bok
Niveau 2
  • 14-05-2024
  • 305weergaven
  • 1reactie

In row 11, what does it mean? and the :

Vraag over de taak Minimum of four numbers
Java Syntax,  Niveau 2,  Les 8
In bespreking

Write a function that computes the minimum of four numbers.
The function min(a, b, c, d) should use (call) the function min(a, b)

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

Vereisten:
  • The program should display text on the screen.
  • The min methods should not display text on the screen.
  • The main method should call min(a, b) and min(a, b, c, d).
  • The main method should display the result of the min methods. Each time, on a new line.
  • The min(a, b) method must return the minimum of the numbers a and b.
  • The min(a, b, c, d) method must use the min(a, b) method.
  • The min(a, b, c, d) method must return the minimum of the numbers a, b, c, and d.
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) { if (min(a, b) < c) { return (min(a, b) <= d) ? min(a, b) : d; } else { return (c <= d) ? c : d; } } public static int min(int a, int b) { return (a <= b) ? a : b; } 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)); } }
+2
Reacties (1)
  • Populair
  • Nieuw
  • Oud
U moet ingelogd zijn om een reactie achter te laten
Hipo7298
Niveau 26 , Kaposvar, Hungary
23 July 2024, 15:25
You can see it in the min of two method too.
public static int min(int a, int b) {
        return (a <= b) ? a : b;
    }
A brief formula to 'if {} else {} ' when you want to check simply things. This 2 below is the same:
public static int min(int a, int b) {
        return (a <= b) ? a : b;
    }
and
public static int min(int a, int b) {
        if (a <= b ) {
              return a;
        }
        else {
              return b;
        }
But i don't recommend to use it when your code grow bigger and more difficult, because that confusing, like this row:
return (min(a, b) <= d) ? min(a, b) : d;
... my first thoght was "what the f*ck is this piece of sh*t?"
+1
Leren
  • Registratie
  • Java-cursus
  • Hulp bij opdrachten
  • Prijzen
  • Java-syntaxis
Community
  • Gebruikers
  • Artikelen
  • Forum
  • Chat
  • Succesverhalen
  • Activiteit
  • Partnerprogramma
Bedrijf
  • Over ons
  • Contacten
  • Beoordelingen
  • Persruimte
  • CodeGym voor EDU
  • Veelgestelde vragen
  • Ondersteuning
CodeGymCodeGym is een online cursus om Java vanaf nul te leren. Deze cursus is een perfecte manier voor beginners om Java te beheersen. Het bevat 1200+ taken met directe verificatie en een essentiële set theorie over Java-grondbeginselen. Om je te helpen slagen, hebben we een reeks motiverende functies geïmplementeerd: quizzen, codeerprojecten, content over efficiënt leren en informatie over de carrière van een Java-ontwikkelaar.
Volg ons
Interface-taal
English Deutsch Español हिन्दी Français Português Polski বাংলা 简体中文 मराठी தமிழ் Italiano Bahasa Indonesia 繁體中文
Nederlands
日本語 한국어 Bulgarian Danish Hungarian Basa Jawa Malay Norwegian Romanian Swedish Telugu Thai Українська Filipino Turkish Azərbaycan Русский Vietnamese
"Programmeurs worden gemaakt, niet geboren" © 2026 CodeGym
MastercardVisa
"Programmeurs worden gemaakt, niet geboren" © 2026 CodeGym