0
Find mistake in this coding
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner cal : new Scanner (System.in); System.out.println("Enter First Value for addition :-") double a : cal.nextDouble( ); System.out.println("Enter Second Value for addition :-") double b : cal.nextDouble( ); double c : a+b; System.out.println("Your Answer is "+c) } }
4 odpowiedzi
+ 11
Replace the colon in the Object, and Variable declaration with the equals sign and add the semicolon after each print statement
+ 3
You must add semicolon (";") at the end of each line, you did it somewhere but not everywhere...
also: you need to replace colon with equal sign when you assign the resul of nextDouble function to the variables "a","b" and "c"
that's the correct one:
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
Scanner cal = new Scanner (System.in);
System.out.println("Enter First Value for addition :-");
double a = cal.nextDouble( );
System.out.println("Enter Second Value for addition :-");
double b = cal.nextDouble( );
double c = a+b;
System.out.println("Your Answer is "+c);
}
}
0
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
Scanner cal : new Scanner (System.in);
System.out.println("Enter First Value for addition :-");
double a : cal.nextDouble( );
System.out.println("Enter Second Value for addition :-");
double b : cal.nextDouble( );
double c : a+b;
System.out.println("Your Answer is "+c);
}
}
now it's output is " No Output "
0
It will be so. You are using double so you need to input two float numbers and add next value under first value in input.
examples
2.4
2.5
Output: 4.9
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
Scanner cal = new Scanner (System.in);
System.out.println("Enter First Value for addition :-");
double a = cal.nextDouble();
System.out.println("Enter Second Value for addition :-");
double b = cal.nextDouble();
double c = a+b;
System.out.println("Your Answer is "+c);
}
}