+ 4
Scanner class of java
Input were not read through scanner object, while running in code playground. Is there any specific reason....
5 Respuestas
+ 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();
}
}
+ 1
Would be easier to say if you posted your code, is your issue with multiple inputs?
+ 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
+ 1
Yes it works. Thank You
+ 1
For input the value from user