0

Do you guys know what the problem is. Please let me know what it is

import java.util.Scanner; class AddNumbers { public static void main(String args[]) { int a,b,c,d,e; int a=2; int b=4; int c=6; int d=8; System.out.print("Enter four even integers to calculate their sum :"); Scanner in = new Scanner(System.in); a=in.nextInt(); b=in.nextInt(); c=in.next.Int(); d=in.next.Int(); e= a+b+c+d; System.out.println("Sum of entered even integers = " + e); } }

3rd Dec 2021, 5:38 PM
Marianne Stevenson
Marianne Stevenson - avatar
14 odpowiedzi
+ 4
Jayakrishna🇮🇳 I was not talking about missing dot (.) 😀😀 nextInt() is a method in scanner class so there should not be dot (.)
3rd Dec 2021, 6:51 PM
A͢J
A͢J - avatar
+ 3
A͢J - S͟o͟l͟o͟H͟e͟l͟p͟e͟r͟ Ya, that was what I was talking about👍
3rd Dec 2021, 6:04 PM
(☞ ಠ_ಠ)☞.ρrΑτΗαΜ.
(☞ ಠ_ಠ)☞.ρrΑτΗαΜ. - avatar
+ 2
Marianne I guess😮, the problem is in the declaration of variables. You have declared it already during -> int a,b,c,d,e; and you declared it once more individually😐. It doesn't make sense😓. I think that should be the problem😅
3rd Dec 2021, 5:46 PM
(☞ ಠ_ಠ)☞.ρrΑτΗαΜ.
(☞ ಠ_ಠ)☞.ρrΑτΗαΜ. - avatar
+ 2
//corrected code import java.util.Scanner; class AddNumbers { public static void main(String args[]) { int a,b,c,d,e; System.out.println("Enter four even integers to calculate their sum :"); Scanner in = new Scanner(System.in); a=in.nextInt(); b=in.nextInt(); c=in.nextInt(); //nextInt(); not next.Int() d=in.nextInt(); e= a+b+c+d; System.out.println("Sum of entered even integers = " + e); } }
3rd Dec 2021, 5:50 PM
Jayakrishna 🇮🇳
+ 2
Jayakrishna🇮🇳 I think, the initialisation of the variables done earlier would be overridden by the values entered, wouldn't it??
3rd Dec 2021, 5:57 PM
(☞ ಠ_ಠ)☞.ρrΑτΗαΜ.
(☞ ಠ_ಠ)☞.ρrΑτΗαΜ. - avatar
+ 2
A͢J - S͟o͟l͟o͟H͟e͟l͟p͟e͟r͟ And thanks for clarifying 😊
3rd Dec 2021, 6:05 PM
(☞ ಠ_ಠ)☞.ρrΑτΗαΜ.
(☞ ಠ_ಠ)☞.ρrΑτΗαΜ. - avatar
+ 2
Learner_Pratham yes. you are right.. A͢J - S͟o͟l͟o͟H͟e͟l͟p͟e͟r͟ Are you taking about next.Int(); dot (.) ×missing?× √edit: extra dot? Yes. I did not check on playground. Edited now... Marianne last 2 lines having next.Int() ; extra a dot(.) a,b, c, d, e are already declared so I commented redefining... edit: not missing. in fact extra dot.
3rd Dec 2021, 6:32 PM
Jayakrishna 🇮🇳
+ 2
Marianne Jayakrishna🇮🇳 Yes, The dot operator shouldn't be there.
3rd Dec 2021, 6:54 PM
(☞ ಠ_ಠ)☞.ρrΑτΗαΜ.
(☞ ಠ_ಠ)☞.ρrΑτΗαΜ. - avatar
+ 2
A͢J - S͟o͟l͟o͟H͟e͟l͟p͟e͟r͟ Oh. Silly mistake..😔 How I write in reverse, I don't know..? May be confused.. 🤔. Thanks. Corrected all now. I will check once in playground..
3rd Dec 2021, 7:08 PM
Jayakrishna 🇮🇳
+ 1
Jayakrishna🇮🇳 You missed 2 more lines where correction should be done.
3rd Dec 2021, 6:02 PM
A͢J
A͢J - avatar
+ 1
Learner_Pratham Yes value will be override but he declared same variable two times.
3rd Dec 2021, 6:03 PM
A͢J
A͢J - avatar
+ 1
Jayakrishna🇮🇳 Yes, I didn't noticed that Marianne as well as you😄 used a dot operator between 'next' and 'Int()'
3rd Dec 2021, 6:35 PM
(☞ ಠ_ಠ)☞.ρrΑτΗαΜ.
(☞ ಠ_ಠ)☞.ρrΑτΗαΜ. - avatar
+ 1
Pay attention to your basic algorithm. Here you apply this algorithm: start : variable: a: int write ("Enter a number") a = read entered number return 4 * a end You only wrote one number and read four times. This is equivalent to reading the only number entered four times. you can store your numbers in a number array using a loop that iterates through the array filling it. Finally you calculate the sum of the numbers stored in your table.
4th Dec 2021, 12:52 PM
Mahatma Tefnakht
Mahatma Tefnakht - avatar
+ 1
When you are taking input for c and d , it should be "in.nextInt()" ... and else it looks fine!
5th Dec 2021, 4:10 AM
Joy