Home  • Programming • Java

How to input integer in java - beginner level

//-----------MyConsoleIO.java----------//
import java.util.Scanner;  // needed for Scanner

    /** A Java program that demonstrates console based input and output. */
    public class MyConsoleIO
    {
        // Create a single shared Scanner for keyboard input
        private static Scanner scanner = new Scanner( System.in );

        // Program execution starts here
        public static void main ( String [] args )
        {
            // Prompt the user
            System.out.print( "Enter your Bengali score: " );
            int bengali = scanner.nextInt();

            System.out.print( "Enter your English score: " );
            int english = scanner.nextInt();

            System.out.print( "Enter your Math score: " );
            int math = scanner.nextInt();

            int total=bengali+english+math;

            // Read a line of text from the user.
           // String input = scanner.nextLine();

            // Display the input back to the user.
            System.out.println( "Total = " + total );

        } // end main method

    } // end MyConsoleIO class

Comments 2


Copyright © 2026. Powered by Intellect Software Ltd