+ 4

Scanner class of java

Input were not read through scanner object, while running in code playground. Is there any specific reason....

30th Jul 2019, 4:42 PM
Sunil Raj
Sunil Raj - avatar
5 ответов
+ 2
Dear Jake, here is the code... import java.util.Scanner; class bignno { int n,max; Scanner s=new Scanner(System.in); public void get() { System.out.println("ENTER NUMBER OF ELEMENT IN THE ARRAY: "); n=s.nextInt(); System.out.println("ENTER THE ELEMENT OF AN ARRAY: "); } public void calc() { int a[]=new int[n]; for(int i=0;i<n;i++) { a[i]=s.nextInt(); } max=a[0]; for(int i=0;i<n;i++) { if(max < a[i]) { max=a[i]; } } } public void disp() { System.out.println("MAXUIMUM VALUE :"+max); } } class big { public static void main(String args[]) { bignno b=new bignno(); b.get(); b.calc(); b.disp(); } }
31st Jul 2019, 4:51 PM
Sunil Raj
Sunil Raj - avatar
+ 1
Would be easier to say if you posted your code, is your issue with multiple inputs?
30th Jul 2019, 5:55 PM
Jake
Jake - avatar
+ 1
Hey, your code works fine, the issue is with the way an online compiler works, you’ll need to enter all the input prior to running the code, so lets say you want to create an array of size 3, then on the first line of input you would write 3, then the next 3 lines after that will be the numbers you store in the array, so in total, the input box when you press run will take 4 lines of integers, for example: 3 21 45 28 and this will return 45 as the greatest number, you would need to scale the amount of lines needed based on the size of the array you want to create, so the example above was an array of size 3 elements, if you wanted to do more, like 5, then you would scale accordingly in the input box: 5 93 12 19 64 14
31st Jul 2019, 8:20 PM
Jake
Jake - avatar
+ 1
Yes it works. Thank You
6th Aug 2019, 8:13 PM
Sunil Raj
Sunil Raj - avatar
+ 1
For input the value from user
13th Aug 2019, 6:41 AM
Hitesh Agrawal