Mega Code Archive

 
Categories / Java Tutorial / Data Type
 

Read Integers from console and calculate

import java.util.Scanner; public class MainClass {    public static void main( String args[] )    {       Scanner input = new Scanner( System.in );       int x;       int y;       int z;       int result;       System.out.print( "Enter first integer: " );       x = input.nextInt();       System.out.print( "Enter second integer: " );       y = input.nextInt();              System.out.print( "Enter third integer: " );       z = input.nextInt();       result = x * y * z;       System.out.printf( "Product is %d\n", result );    } } Enter first integer: 1 Enter second integer: 2 Enter third integer: 3 Product is 6