CodeGym
Promotion
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
andy 6473
Level 9
Bangalore
  • 18.06.2020
  • 337views
  • 1comment

help me with this stupid program

Question about the task Task about algorithms
Java Syntax,  Level 5,  Lesson 12
Resolved

Write a program that:
1. reads a number N (must be greater than 0) from the console
2. reads N numbers from the console
3. Displays the maximum of the N entered numbers.

Requirements:
  • The program should read the numbers from the keyboard.
  • The program must display a number on the screen.
  • The class must have a public static void main method.
  • Don't add new methods to the Solution class.
  • The program should display the maximum of the N entered numbers.
  • The program should not display anything if N is less than or equal to 0.
package com.codegym.task.task05.task0532; import java.io.*; /* Task about algorithms */ public class Solution { public static void main(String[] args) throws Exception { BufferedReader reader = new BufferedReader(new InputStreamReader (System.in)); // System.out.println ("Enter the amount of numbers to be scanned"); int n = Integer.parseInt ( reader.readLine () ); // System.out.println ( "Entered value for n is "+n ); int leastNum[] = new int[n]; // System.out.println ("Array size is "+leastNum); // for reading the data from keyboard least num array is declared // this array is fed from the keyboard . if(n > 0){ for(int i = 0; i < n ; i++){ leastNum[i]=Integer.parseInt ( reader.readLine () ); // System.out.println ("Value stored at "+ i+ "Location is"+leastNum[i]); } // System.out.println ("Least num length is "+leastNum.length); int maximum = Integer.MIN_VALUE; // System.out.println ("intial value of maximum is "+maximum); for(int i =0 ; i < n; i++){ if(maximum < leastNum[i]){ maximum = leastNum[i]; } } System.out.println(maximum); } else if(n <= 0){ } } }
0
Comments (1)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Cynthia
Level 16
22 June 2020, 15:49
Try and remove the else if statement because it's not doing anything
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.