Java - Two ways to take input

//1. Command Line
//2. Scanner Class
import java.util.Scanner;
class Test{
public static void main(String ar[]){
int a,b,sum;

Scanner scan=new Scanner(System.in);
//a=Integer.parseInt(ar[0]);// For command line
//b=Integer.parseInt(ar[1]);// For Command line
System.out.printf("Enter a\n");
a=scan.nextInt();
System.out.printf("Enter b\n");
b=scan.nextInt();
sum=a+b;
System.out.println("Sum="+sum);
}

}

Reactions:

0 comments:

Post a Comment