CodeGym
CodeGym University
Learning
Course
Tasks
Surveys & Quizzes
Games
Help
Schedule
Community
Users
Forum
Chat
Articles
Success stories
Activity
Reviews
Subscriptions
Light theme
Start learning now
  • All questions
Rich
Level 23
San Diego
  • 17.09.2020
  • 286views
  • 1comment

ternary

Question about the task Three methods and a minimum
Java Core,  Level 2,  Lesson 4
Resolved

Write the following public static methods: int min(int, int), long min(long, long), double min(double, double).
Each method must return the minimum of the two numbers passed to it.

Requirements:
  • The program should not display text on the screen.
  • The Solution class must have four methods.
  • The Solution class must have a static int min(int, int) method.
  • The int min(int, int) method must return the minimum of two ints.
  • The Solution class must have a static long min(long, long) method.
  • The long min(long, long) method must return the minimum of two longs.
  • The Solution class must have a static double min(double, double) method.
  • The double min(double, double) method must return the minimum of two doubles.
package com.codegym.task.task12.task1209; import java.util.*; /* Three methods and a minimum */ public class Solution { public static void main(String[] args) { } public static int min(int a, int b){ a<b ? return a : return b; } public static long min(long a, long b){ a <b ?return a : return b; } public static double min(double a, double b){ a<b ?return a : return b; } //write your code here }
0
Comments (1)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Nouser
Level 36 , Germany
18 September 2020, 06:36
Ternary operator isn't used this way. It's used to assign values.
int c =  a < b ? a : b;
or
return  a < b ? a : b;
And it's hard to assign eg. return a
+1
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.