0
Sponsored Links


Ad by Google
Very basic java coding practice or java homework questions. While learning Java, we started with converting basic calculation to using Java program. like creating calculator using Java code, printing sum of digits and all. And sometimes this type of questions also asked in core Java written interview questions, although this question is not as demanded as how to balanced the parentheses using Java program.

package com.javamakeuse.poc;

import java.util.Scanner;

/**
 * 
 * @author javamakeuse
 *
 */
public class Number {
 public static void main(String[] args) {
  try (Scanner scanner = new Scanner(System.in)) {
   System.out.println("Enter first number ");
   int a = scanner.nextInt();
   System.out.println("Enter second number");
   int b = scanner.nextInt();
   int c = a + b;
   System.out.printf("sum of %d and %d is %d", a, b, c);
  }
 }
}


OUTPUT:
Enter first number
4
Enter second number
4
sum of 4 and 4 is 8
Sponsored Links

0 comments:

Post a Comment