1.Write a program add two numbers.
class SriHari
{
public static void main(String args[ ])
{
int a=5,b=6,c=0;
c=a+b;
System.out.println("adition is"+c);
}
}
2.Add two numbers using command line arguments
class SriHari
{
public static void main(String args[ ])
{
int a,b,c=0;
a=Integer.parseInt(args[0]);
b=Integer.parseInt(args[1]);
c=a+b;
System.out.println("adition is"+c);
}
}
3.Add two numbers using Scanner class method.
import java.util.Scanner;
class SriHari
{
public static void main(String args[])
{
int a,b,c=0;
Scanner sc = new Scanner(System.in);
System.out.print("Enter the first number");
a=sc.nextInt();
System.out.print("Enter the second number");
b=sc.nextInt();
c=a+b;
System.out.println("addition is"+c);
}
}
No comments:
Post a Comment