how to solve it an integer can only contain list of no. if it is an array .
othervise not possible .
give me some advice how to solve this question.
Give me some advice how to solve this question
@Harsh_Sonwani
in order to take input a single integer, you can use
int a=scn.nextInt();
and if you want to take list of no. as input then
int a[]=new int[n];//create an array of size n
for(int i=0;i<n;i++){
a[i]=scn.nextInt();//take integer input at each index i
}
i have not studied array till now so how can i solve this
Hi @Harsh_Sonwani,
This does not require you to use a array just take a integer input and add it to sum variable which is initialized to zero and then put a while loop checking till the time sum becomes negative …
Something like this.
int sum = 0;
int a = scn.nextInt();
sum=sum+a;
while(sum>=0){
a = scn.nextInt();
sum=sum+a;
}
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.