BASIC JAVA PROGRAMMING
1. Write a program to add, subtract, multiply and divide 2 numbers .
/* Add 2 numbers */
class Add{
public static void main(String args[])
{
int a=12;
int b=6;
int sum=a+b;
System.out.println("The sum of two numbers is " +sum);
}
}
/* Subtract 2 numbers */
class Subtract
{
public static void main(String args[])
{
int a=12;
int b=6;
int sub=a-b;
System.out.println("The difference of two numbers is " +sub);
}
}
/* Multiply 2 numbers */
class Multiply
{
public static void main(String args[])
{
int a=12;
int b=6;
int pr=a*b;
System.out.println("The product of two numbers is " +pr);
}
}
/* Divide 2 numbers */
class Divide
{
public static void main(String args[])
{
int a=12;
int b=6;
int div=a/b;
System.out.println("Dividing 2 numbers we get " +div);
}
}
2. Write a program to find greatest of 2 numbers
class Greatest
{
public static void main(String args[])
{
int a=5,b=6;
int greatest = a>b?a:b;
System.out.println(greatest);
}
}
3. Write a program to find the number of 2000,500 and 100 rupee notes from a given denomination
import java.io.*;
class Denomination
{
public static void main(String args[])
{
int a=Integer.parseInt(args[0]);
int x=a/2000;
System.out.println("2000* "+x);
a=a%2000;
x=a/500;
System.out.println("500* "+x);
a=a%500;
x=a/100;
System.out.println("100* "+x);
}
}
Comments
Post a Comment