Do you guys know what the problem is. Please let me know what it is | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
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 Respostas
+ 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
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