Finding the largest number | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Finding the largest number

Hi, Can anyone please let me know where I went wrong with the Java code? I am getting memory exceeded message. Thanks import java.util.Scanner; class Largestnumber { public static void main(String[] args){ int a=0,b=0,c=0; int largest; Scanner X = new Scanner(System.in); System.out.println("Enter number for a"); a=X.nextInt(); System.out.println("Enter number for b"); b=X.nextInt(); System.out.println("Enter number for c"); c=X.nextInt(); if (a>b & a>c) largest =a; else if (b>a & b>c) largest =b; else largest =c; System.out.println("Largest is" +largest); } }

14th Feb 2018, 5:03 PM
Gayatri
4 Answers
+ 2
It works fine for me. It might happen sometimes. I think one guy said, that it's because of Sololearn's restrictive memory limit. It would work fine on a computer
14th Feb 2018, 6:25 PM
Sad
Sad - avatar
+ 2
Your welcome☺👍
15th Feb 2018, 9:07 AM
Sad
Sad - avatar
+ 1
Thanks for your reply, have you tried all conditions? The place of error message changes with various values.
15th Feb 2018, 3:55 AM
Gayatri
+ 1
Hi ,it is working on desktop. Thanks for your help.
15th Feb 2018, 9:06 AM
Gayatri