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); } }
14 Answers
+ 4
Jayakrishna🇮🇳
I was not talking about missing dot (.) 😀😀
nextInt() is a method in scanner class so there should not be dot (.)
+ 3
A͢J - S͟o͟l͟o͟H͟e͟l͟p͟e͟r͟ Ya, that was what I was talking about👍
+ 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😅
+ 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);
}
}
+ 2
Jayakrishna🇮🇳 I think, the initialisation of the variables done earlier would be overridden by the values entered, wouldn't it??
+ 2
A͢J - S͟o͟l͟o͟H͟e͟l͟p͟e͟r͟ And thanks for clarifying 😊
+ 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.
+ 2
Marianne Jayakrishna🇮🇳 Yes, The dot operator shouldn't be there.
+ 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..
+ 1
Jayakrishna🇮🇳
You missed 2 more lines where correction should be done.
+ 1
Learner_Pratham
Yes value will be override but he declared same variable two times.
+ 1
Jayakrishna🇮🇳 Yes, I didn't noticed that Marianne as well as you😄 used a dot operator between 'next' and 'Int()'
+ 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.
+ 1
When you are taking input for c and d , it should be "in.nextInt()" ... and else it looks fine!