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
Alex Balandinos
Level 18
Lusaka
  • 08.03.2019
  • 1178views
  • 5comments

Numbers are displayed in decreasing Oder failing verify

Question about the task In decreasing order
Java Syntax,  Level 7,  Lesson 12
Under discussion


Task: Write a program that reads 20 numbers from the keyboard and displays them in decreasing order.

Requirements:
  • The program should read 20 integers from the keyboard.
  • The program should display 20 numbers.
  • The Solution class must have a public static void sort(int[] array) method.
  • The main method should call the sort method.
  • The sort method should sort the passed array in decreasing order.
package com.codegym.task.task07.task0728; import java.io.BufferedReader; import java.io.InputStreamReader; /* In decreasing order */ public class Solution { public static void main(String[] args) throws Exception { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int[] array = new int[20]; for (int i = 0; i < 20; i++) { array[i] = Integer.parseInt(reader.readLine()); } sort(array); for (int x : array) { System.out.println(x); } } public static void sort(int[] array) { //write your code here for(int j = 0; j<array.length; j++){ array[j] = 20 - j; } } }
0
Comments (5)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Koniasz
Level 22 , Warszawa, Polska
17 July 2019, 01:04
public static void sort(int[] array) { int n = array.length; int temp = 0; for (int i = 0; i < n; i++) { for (int j = 1; j < (n - i); j++) { if (array[j - 1] < array[j]) { //swap the elements! temp = array[j - 1]; array[j - 1] = array[j]; array[j] = temp; } } } }
+1
Khurram
Level 16 , Lahore, Pakistan
8 March 2019, 16:52
you are not supposed to display the numbers 1 to 20 in decreasing order. You are asked to sort the numbers entered by the user. if i enter (1,1,2,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10) the code displays 20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1, though i have not entered the numbers 11..20
0
Alex Balandinos
Level 18 , Lusaka, Zambia
8 March 2019, 18:07
That's exactly what my code does its correct
0
Guadalupe Gagnon
Level 37 , Tampa, United States
8 March 2019, 18:23
If you enter the numbers: 1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10 the output should be: 10,10,9,9,8,8,7,7,6,6,5,5,4,4,3,3,2,2,1,1
0
Khurram
Level 16 , Lahore, Pakistan
9 March 2019, 04:43
for any set of inputs, your code will always display 1 to 20 in descending order. you are not actually sorting anything. you are just displaying the numbers 1 to 20
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.