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
Kazer Panol
Level 7
  • 08.05.2020
  • 361views
  • 2comments

Whats wrong with my code?Please help

Question about the task Maximum of four numbers
Java Syntax,  Level 4,  Lesson 6
Under discussion

Use the keyboard to enter four numbers, and display the maximum of them. If the maximum occurs more than once, just display it once.

Requirements:
  • The program should read the numbers from the keyboard.
  • The program must display a number on the screen.
  • The program should display the maximum of four numbers.
  • If there are several maximum numbers, display any of them.
package com.codegym.task.task04.task0419; /* Maximum of four numbers */ import java.io.*; import java.util.Scanner; public class Solution { public static void main(String[] args) throws Exception { //write your code here Scanner in = new Scanner(System.in); int fnum =1; int snum =1; int tnum =1; int fonum =2; int temp=0; int arr[]={fnum,snum,tnum,fonum}; for(int i=0; i<arr.length;i++){ if(arr[i]>temp){ temp=arr[i]; }} System.out.println(temp); } }
0
Comments (2)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Kazer Panol
Level 7 , Philippines
8 May 2020, 10:13
Thanks it works correctly.
0
Ashish RajAnand
Level 13 , Bhilai , India
8 May 2020, 00:50
1-Where you take input from keyword . 2-you must assign first number to temp variable to work correct with negative number .
+2
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.