Help me spot the error in my code lines | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Help me spot the error in my code lines

import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner cal = new Scanner (System.in); Double fnum, snum, answer; System.out.println ("Enter your first value"); fnum = cal.nextDouble(); System.out.println ("Enter your second value"); snum = cal.nextDouble(); answer = fnum + snum; System.out.println (answer); } } this code is supposed to be a simple addition program but it doesn't seem to work.

5th May 2017, 11:16 PM
Peter Claver
Peter Claver - avatar
2 Answers
+ 12
It works just fine. Maybe you are confused because code playground takes all the values at the beginning before executing the rest of the code. Input both double values in the window that pops up. One value each line, separated by a line break.
5th May 2017, 11:46 PM
Tashi N
Tashi N - avatar
+ 2
Thanks it did work
6th May 2017, 12:42 PM
Peter Claver
Peter Claver - avatar