Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js
Home  • Programming • Java

How to input integer in java - beginner level

//-----------MyConsoleIO.java----------//
  1. import java.util.Scanner; // needed for Scanner
  2.  
  3. /** A Java program that demonstrates console based input and output. */
  4. public class MyConsoleIO
  5. {
  6. // Create a single shared Scanner for keyboard input
  7. private static Scanner scanner = new Scanner( System.in );
  8.  
  9. // Program execution starts here
  10. public static void main ( String [] args )
  11. {
  12. // Prompt the user
  13. System.out.print( "Enter your Bengali score: " );
  14. int bengali = scanner.nextInt();
  15.  
  16. System.out.print( "Enter your English score: " );
  17. int english = scanner.nextInt();
  18.  
  19. System.out.print( "Enter your Math score: " );
  20. int math = scanner.nextInt();
  21.  
  22. int total=bengali+english+math;
  23.  
  24. // Read a line of text from the user.
  25. // String input = scanner.nextLine();
  26.  
  27. // Display the input back to the user.
  28. System.out.println( "Total = " + total );
  29.  
  30. } // end main method
  31.  
  32. } // end MyConsoleIO class

Comments 2


  1. import java.util.Scanner;
  2.  
  3. public class Manager {
  4.  
  5. public static void main(String[] args) {
  6.  
  7.  
  8. ShowMessag Tushar=new ShowMessag();
  9.  
  10. TakeInput Tushar1=new TakeInput();
  11.  
  12. Tushar.BanglaMarks();
  13. Tushar1.BanglaInput();
  14.  
  15.  
  16. Tushar.EnglishMarks();
  17. Tushar1.EnglishInput();
  18.  
  19.  
  20. Tushar.MathMarks();
  21. Tushar1.MathMarks();
  22.  
  23. Tushar1.TotalMarks();
  24.  
  25. }
  26.  
  27. }
  28.  
  29. class ShowMessag {
  30.  
  31. public void BanglaMarks(){
  32. System.out.println("Give Bangla Marks");
  33. }
  34.  
  35. public void EnglishMarks(){
  36. System.out.println("Give English Marks");
  37. }
  38.  
  39. public void MathMarks(){
  40. System.out.println("Give Math Marks");
  41. }
  42.  
  43.  
  44. }
  45.  
  46. class TakeInput {
  47.  
  48. int bengali;
  49. int english;
  50. int math;
  51.  
  52. private static Scanner scanner = new Scanner( System.in );
  53.  
  54. public TakeInput(){
  55. this.bengali=0;
  56. this.english=0;
  57. this.math=0;
  58. }
  59.  
  60. public void BanglaInput(){
  61. bengali = scanner.nextInt();
  62. }
  63.  
  64. public void EnglishInput(){
  65. english = scanner.nextInt();
  66. }
  67.  
  68.  
  69. public void MathMarks(){
  70. math = scanner.nextInt();
  71. }
  72.  
  73. public void TotalMarks(){
  74. System.out.println("Total="+bengali+english+math);
  75. }
  76.  
  77. }
this above code example was incomplete and sent by one of my NCC student and i just solve his problem so that i paste it here.
Copyright © 2025. Powered by Intellect Software Ltd