Java Practical Mcasem-II.docx
Java Practical Mcasem-II.docx
class HelloWorld {
System.out.println("Hello World!");
/*P2 Write a java program to add, sub,multiply and divide two integers
numbers.*/
float devide;
class Swap
x=10;
y=20;
t = x;
x = y;
y = t;
System.out.println( );
//P4 Write a java Program to Check the Number is Positive, Negative or Zero
int num=912;
if(num>0)
else if(num<0)
else
int num=20;
if(num % 2 == 0)
else
//P6 Write a java Program to find the maximum and minimum of three numbers
int num3 = 7;
else
/*PL 7 (1.2) Write a simple java application to print a pyramid with 5 lines.
The first line has one character; the second line has two characters and so on.
int i, j, n=5;
System.out.print("* ");
System.out.println();
} }
//PL8 (1.1) Write a java Program to find the sum of all integers than 100 & less
than 200 and are divisible by 5
if(i%5==0)
sum=sum+i;
count++;
import java.util.Scanner;
float a, b, res;
int choice;
System.out.println("1. Addition");
System.out.println("2. Subtraction");
System.out.println("3. Multiplication");
System.out.println("4. Division");
choice = scan.nextInt();
a = scan.nextFloat();
b = scan.nextFloat();
if(choice==1)
res = a+b;
else if(choice==2)
res = a-b;
else if(choice==3)
res = a*b;
else
res = a/b;
else
System.out.println("\nInvalid Choice!");
/*PL10 (1.3) Write a Java application which takes several command line
arguments, which are supposed to be the names of students and prints output
as given below: Number of arguments = 3 1: Tom 2: Dick 3: Harry */
class CommLine
for(int i=0;i<a.length;i++)
class FactorialExample{
int i,factorial=1;
int n = 8;
for(i=1;i<=n;i++){
factorial = factorial*i;
class FibonacciWithoutRecursion{
System.out.print(number1+" "+number2);
number3 = number1+number2;
System.out.print(" "+number3);
number1 = number2;
number2 = number3;
//P13 Write a java Program to checked given number is a Prime number or Not
int i,m=0,flag=0;
m=n/2;
if(n==0||n==1)
else
for(i=2;i<=m;i++)
if(n%i==0)
flag=1;
break;
if(flag==0)
class Testarray
int a[]={10,20,70,40,50};
for(int i=0;i<a.length;i++)
System.out.println(a[i]);
int temp = 0;
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
System.out.println();