CodeGym
Promotion
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
NOBODY
Level 5
  • 07.05.2020
  • 373views
  • 1comment

help please

Question about the task Somehow average
Java Syntax,  Level 4,  Lesson 16
Under discussion

Use the keyboard to enter three numbers, and then display the middle number.
In other words, not the largest and not the smallest.
If all the numbers are equal, display any one of them.

Requirements:
  • The program should read the numbers from the keyboard.
  • The program must display a number on the screen.
  • The program should display the middle number of the three numbers.
  • If all the numbers are equal, display any one of them.
  • If two of the three numbers are equal, display either of the two.
package com.codegym.task.task04.task0441; /* Somehow average */ import java.io.*; public class Solution { public static void main(String[] args) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int a = Integer.parseInt(in.readLine()); int b = Integer.parseInt(in.readLine()); int c = Integer.parseInt(in.readLine()); if(a >= b && a <= c){ System.out.println(a); } else if(a > b && b > c && c < a){ System.out.println(b); } if(b >= a && b <= c){ System.out.println(b); } else if(a > b && b < c && c != a){ System.out.println(c); } else if(b > a && b > c){ System.out.println(b); } if(c >= a && c <= b){ System.out.println(c); } else if(c > a && c > b){ System.out.println(c); } if(a == b || a == c){ System.out.println(a); } else if(b == a || b == c){ System.out.println(b); } else if(c == a || c == b){ System.out.println(c); } else { System.out.println(a); } } }
0
Comments (1)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Patryk
Level 15 , Katowice, Poland
7 May 2020, 12:26
please my code : if(isEqual(first, second) == 0) { //first, second System.out.println(first); } else if(isEqual(second, third) == 0) { //second , third System.out.println(second); } else if( ( (isEqual(first,second) > 0) && (isEqual(first,third) < 0) ) || ( (isEqual(first,third) > 0) && (isEqual(first,second) < 0) ) ) { System.out.println(first); } else if( ( (isEqual(second,first) > 0) && (isEqual(second,third) < 0) ) || ( (isEqual(second,third) > 0) && (isEqual(second,first) < 0) ) ) { System.out.println(second); } else if( ( (isEqual(third,first) > 0) && (isEqual(third,second) < 0) ) || ( (isEqual(third,second) > 0) && (isEqual(third,first) < 0) ) ) { System.out.println(third); } else { System.out.println(third); } } public static int isEqual(int first, int second) { if(first > second) { return 1; //large } else if (first < second) { return -1; //small } else { return 0; // equals } }
+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.