Posted by : Unknown
Monday, 15 June 2015
{
public static void main( String args[] )
{
Scanner input = new Scanner( System.in );
int number1,number2,sum;
System.out.print( "Enter first integer: " );
number1 = input.nextInt();
Scanner input = new Scanner( System.in );
int number1,number2,sum;
System.out.print( "Enter first integer: " );
number1 = input.nextInt();
System.out.print( "Enter second integer: " );
number2 = input.nextInt();
sum = number1 + number2;
System.out.println("Sum is: " + sum );
}
}
number2 = input.nextInt();
sum = number1 + number2;
System.out.println("Sum is: " + sum );
}
}
Use "printf" function in java. Its also working.
import java.util.Scanner;
class addition
class addition
{
public static void main( String args[] )
{
Scanner input = new Scanner( System.in );
int number1,number2,sum;
System.out.print( "Enter first integer: " );
number1 = input.nextInt();
Scanner input = new Scanner( System.in );
int number1,number2,sum;
System.out.print( "Enter first integer: " );
number1 = input.nextInt();
System.out.print( "Enter second integer: " );
number2 = input.nextInt();
sum = number1 + number2;
System.out.printf( "Sum is: %d\n", sum );
}
}
number2 = input.nextInt();
sum = number1 + number2;
System.out.printf( "Sum is: %d\n", sum );
}
}
Use following code also:
import java.util.Scanner;
class addition
class addition
{
public static void main( String args[] )
{
Scanner input = new Scanner( System.in );
int number1,number2;
System.out.print( "Enter first integer: " );
number1 = input.nextInt();
Scanner input = new Scanner( System.in );
int number1,number2;
System.out.print( "Enter first integer: " );
number1 = input.nextInt();
System.out.print( "Enter second integer: " );
number2 = input.nextInt();
System.out.printf( "Sum is: %d\n", ( number1 + number2 ) );
}
}
number2 = input.nextInt();
System.out.printf( "Sum is: %d\n", ( number1 + number2 ) );
}
}
Output:
Enter first integer: 54
Enter second integer: 47
Sum is: 101
Related Posts :
- Back to Home »
- Example program »
- Addition - Sum of two numbers - Get input from user