2016 All PROGRAMS
IMPOTENT NOTES :-
1) . I Witted All Programs Definition in short Be Adjust your self
2) . Project file color is "RED"
3) . Some Programs are upload as soon as possible
1. Write a program that pass command line arguments of name different students.Arrange them name wise in ascending order.
import java.io.*;
import java.util.*;
class studentaces
{
public static void main(String args[])
{
Scanner s = new Scanner(System.in);
System.out.println("how many Student Insert:-");
int n = s.nextInt();
String arr[] = new String[n];
for(int i=0;i<n;i++)
{
System.out.println("Enter the Student Name:-");
arr[i] = s.next();
}
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
if(arr[i].compareTo(arr[j])>0)
{
String temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
System.out.println("After Sorting:");
for(int i=0;i<n;i++)
{
System.out.println(arr[i]);
}
}
}
2.
Write a program that generates ArraylndexOutOfBounds Exception, catch the exception and Display an Error Messages.
import java.lang.Exception;
public class arraytest
{
public static void main (String args[])
{
try
{
int array[] = {2};
array[3] = 33;
/*int array[] = new int[2];
array[0] = 1;
array[1] = 2;
array[2] = 3;*/
for(int i =0;i <array.length; i++)
{
System.out.println("The value of Array is:-" +array[i]);
}
}
catch (ArrayIndexOutOfBoundsException e)
{
System.out.println("Array is out of Bounds");
}
}
}
3.
Write a program to accept a string and count total number of upper case character and lower case character in a string.
import java.io.*;
public class countstring
{
public static void main(String args[])
{
String str = "HelloWorld";
System.out.println("\n");
System.out.println("Main String is :-" +str);
int s1 = str.length();
String upper = "";
String lower = "";
for(int i=0;i<str.length();i++)
{
char find = str.charAt(i);
if(find >= 65 && find <= 90)
{
upper = upper + find;
}
else
{
lower = lower + find;
}
}
System.out.println("Total Length Of String is :-"+s1);
System.out.println("UPPERCASE Character is:-");
System.out.println(upper);
System.out.println("LOWERCASE Character is:-");
System.out.println(lower);
}
}
4.
Write a program that generates a custom exception if any inputted value is not in limit of -5 to +5.
import java.lang.Exception;
class CustomException extends Exception
{
CustomException(String msg)
{
super(msg);
}
}
class custom
{
public static void main(String args[])
{
try
{
int a = Integer.parseInt(args[0]);
if(a >= -5 && a <=5)
{
System.out.println("Your Entered Value is :"+a);
}
else
{
throw new CustomException("Values is Not Between -5 to 5");
}
}
catch(CustomException e)
{
System.out.println(e);
}
}
}
5.
Write a program that generates a custom exception if any of its commands line arguments are floating point number.
import java.lang.Exception;
class CustomException extends Exception
{
CustomException(String msg)
{
super(msg);
}
}
class floattest
{
public static void main(String args[])
{
try
{
try
{
int a = Integer.parseInt(args[0]);
}
catch(NumberFormatException e)
{
throw new CustomException("Entered Values are in Float Format ");
}
}
catch(CustomException e)
{
System.out.println(e);
}
}
}
6.
Write a java code to create package ______ "stud" in which create a class "Student' which contain information Roll No and name of students. Create another package "marks" in which create a class "Studmarks" which extend from 'Student" and it contain instances variable say marks of three subjects. Write a Java code to store main() in different package and required argument through command line. [UPDATED if you made it then send to me or upload here ->UPLOAD ]
3) . Some Programs are upload as soon as possible
1. Write a program that pass command line arguments of name different students.Arrange them name wise in ascending order.
import java.io.*;
import java.util.*;
class studentaces
{
public static void main(String args[])
{
Scanner s = new Scanner(System.in);
System.out.println("how many Student Insert:-");
int n = s.nextInt();
String arr[] = new String[n];
for(int i=0;i<n;i++)
{
System.out.println("Enter the Student Name:-");
arr[i] = s.next();
}
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
if(arr[i].compareTo(arr[j])>0)
{
String temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
System.out.println("After Sorting:");
for(int i=0;i<n;i++)
{
System.out.println(arr[i]);
}
}
}
2.
Write a program that generates ArraylndexOutOfBounds Exception, catch the exception and Display an Error Messages.
import java.lang.Exception;
public class arraytest
{
public static void main (String args[])
{
try
{
int array[] = {2};
array[3] = 33;
/*int array[] = new int[2];
array[0] = 1;
array[1] = 2;
array[2] = 3;*/
for(int i =0;i <array.length; i++)
{
System.out.println("The value of Array is:-" +array[i]);
}
}
catch (ArrayIndexOutOfBoundsException e)
{
System.out.println("Array is out of Bounds");
}
}
}
3.
Write a program to accept a string and count total number of upper case character and lower case character in a string.
import java.io.*;
public class countstring
{
public static void main(String args[])
{
String str = "HelloWorld";
System.out.println("\n");
System.out.println("Main String is :-" +str);
int s1 = str.length();
String upper = "";
String lower = "";
for(int i=0;i<str.length();i++)
{
char find = str.charAt(i);
if(find >= 65 && find <= 90)
{
upper = upper + find;
}
else
{
lower = lower + find;
}
}
System.out.println("Total Length Of String is :-"+s1);
System.out.println("UPPERCASE Character is:-");
System.out.println(upper);
System.out.println("LOWERCASE Character is:-");
System.out.println(lower);
}
}
4.
Write a program that generates a custom exception if any inputted value is not in limit of -5 to +5.
import java.lang.Exception;
class CustomException extends Exception
{
CustomException(String msg)
{
super(msg);
}
}
class custom
{
public static void main(String args[])
{
try
{
int a = Integer.parseInt(args[0]);
if(a >= -5 && a <=5)
{
System.out.println("Your Entered Value is :"+a);
}
else
{
throw new CustomException("Values is Not Between -5 to 5");
}
}
catch(CustomException e)
{
System.out.println(e);
}
}
}
5.
Write a program that generates a custom exception if any of its commands line arguments are floating point number.
import java.lang.Exception;
class CustomException extends Exception
{
CustomException(String msg)
{
super(msg);
}
}
class floattest
{
public static void main(String args[])
{
try
{
try
{
int a = Integer.parseInt(args[0]);
}
catch(NumberFormatException e)
{
throw new CustomException("Entered Values are in Float Format ");
}
}
catch(CustomException e)
{
System.out.println(e);
}
}
}
6.
Write a java code to create package ______ "stud" in which create a class "Student' which contain information Roll No and name of students. Create another package "marks" in which create a class "Studmarks" which extend from 'Student" and it contain instances variable say marks of three subjects. Write a Java code to store main() in different package and required argument through command line. [UPDATED if you made it then send to me or upload here ->UPLOAD ]
package stud;
public class student
{
int rollno;
String name;
public student(int
r,String n)
{
rollno=r;
name=n;
}
public void display()
{
System.out.println("Roll_no:-"+rollno);
System.out.println("Name:-"+name);
}
}
package marks;
public class studmarks
{
int
mark1,mark2,mark3;
public
void studdata(int a,int b,int c)
{
mark1
= a;
mark2
= b;
mark3
= c;
}
public
void display()
{
System.out.println("Marks
1 :-"+mark1);
System.out.println("Marks
2 :-"+mark2);
System.out.println("Marks
3 :-"+mark3);
}
}
import stud.*;
import marks.*;
class studtest
{ public
static void main(String args[])
{ int m1,m2,m3;
m1
= Integer.parseInt(args[0]);
m2
= Integer.parseInt(args[1]);
m3
= Integer.parseInt(args[2]);
student
s1 = new student(1,"Piyush");
s1.display();
studmarks
s2 = new studmarks();
s2.studdata(m1,m2,m3);
s2.display();
}
}
7.Write a java code that will read a string and rewrite it in alphabetical order
import java.io.*;
public class stringorder
{
static String n = "BCA";
static int l;
public static void main(String args[]) throws IOException
{
l = n.length();
char b[] = new char[l];
for(int i=0;i<l;i++)
{
b[i] = n.charAt(i);
}
char t;
for(int j=0;j<l-1;j++)
{
for(int k=0;k<l-1-j;k++)
{
if(b[k]>b[k+1])
{
t=b[k];
b[k]=b[k+1];
b[k+1]=t;
}
}
}
System.out.println("\nOriginal word : " +n);
System.out.print("Sorted word : ");
for(int m=0;m<l;m++)
{
System.out.print(b[m]);
}
}
}
public class stringorder
{
static String n = "BCA";
static int l;
public static void main(String args[]) throws IOException
{
l = n.length();
char b[] = new char[l];
for(int i=0;i<l;i++)
{
b[i] = n.charAt(i);
}
char t;
for(int j=0;j<l-1;j++)
{
for(int k=0;k<l-1-j;k++)
{
if(b[k]>b[k+1])
{
t=b[k];
b[k]=b[k+1];
b[k+1]=t;
}
}
}
System.out.println("\nOriginal word : " +n);
System.out.print("Sorted word : ");
for(int m=0;m<l;m++)
{
System.out.print(b[m]);
}
}
}
8.
Write a code which accepts names depending on user's choice stored into array and display those names having length greater than 10.
import java.util.*;
class bigstring
{
public static void main(String args[])
{
Scanner s = new Scanner(System.in);
System.out.println("How many String you Input:-");
int n = s.nextInt();
String name[] = new String[n];
for(int i=0;i<n;i++)
{
System.out.println("\n");
System.out.print("Enter the Name:-"+(i+1)+":");
name[i]=s.next();
}
for(int i=0;i<n;i++)
{
int len = name[i].length();
if(len >= 10)
{
System.out.println("Entered Names:-"+name[i]);
}
}
}
}
9.
Write code to accept a number through command Line & check whether is palindrome or not.
Write a code which accepts names depending on user's choice stored into array and display those names having length greater than 10.
import java.util.*;
class bigstring
{
public static void main(String args[])
{
Scanner s = new Scanner(System.in);
System.out.println("How many String you Input:-");
int n = s.nextInt();
String name[] = new String[n];
for(int i=0;i<n;i++)
{
System.out.println("\n");
System.out.print("Enter the Name:-"+(i+1)+":");
name[i]=s.next();
}
for(int i=0;i<n;i++)
{
int len = name[i].length();
if(len >= 10)
{
System.out.println("Entered Names:-"+name[i]);
}
}
}
}
9.
Write code to accept a number through command Line & check whether is palindrome or not.
import java.io.*;
class check
{
public static void main(String args[])
{
int no = Integer.parseInt(args[0]);
int n = no;
int rev=0,rem;
while(no > 0)
{
rem = no % 10;
rev = rev * 10 + rem;
no = no / 10;
}
if(rev == n)
{
System.out.println(n+" is a Palindrome Number");
}
else
{
System.out.println(n+" is not a Palindrome Number");
}
}
}
10.
Write Program to accept names of employee and their salary. Sort the record in descending order based on their salary.
import java.util.Scanner;
class descsort
{
public static void main(String args[])
{
Scanner s = new Scanner(System.in);
System.out.println("How many Employee Insert:-");
int n;
n = s.nextInt();
int no[] = new int[n];
String name[] = new String[n];
System.out.println("\n");
for(int i=0;i<n;i++)
{
System.out.print("Enter the Employee Name "+(i+1)+":");
name[i] = s.next();
System.out.print("Enter the Employee Salary "+(i+1)+":");
no[i] = s.nextInt();
System.out.println("\n");
}
System.out.println("________________List of Employee____________");
for(int i=0;i<n;i++)
{
System.out.println("Enter the Employee No"+(i+1)+":"+no[i]);
System.out.println("Enter the Employee Name"+(i+1)+":"+name[i]);
System.out.println("________________");
}
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
if(no[i]<no[j])
{
int t = no[i];
no[i] = no[j];
no[j] = t;
String temp = name[i];
name[i] = name[j];
name[j] = temp;
}
}
}
System.out.println("\n");
System.out.println("___________________Sorting________________");
for(int i=0;i<n;i++)
{
System.out.println("Enter the Employee No"+(i+1)+":"+no[i]);
System.out.println("Enter the Employee Name"+(i+1)+":"+name[i]);
System.out.println("______________");
}
}
}
11.
Write an Application that creates and start three threads. Each thread is instantiated from the same class. It executes a loop with 10 iteration. Each iteration displays the character 'A' and sleep between 300 to 500 millisecond. The application waits for all the thread to complete and then display a message.
12. Write a applet to display a house.
13. Write a applet to display a house.
14.
Write Program to Applet a User input two value and get the Sum of two value.
15.
Write Program to Applet which Display the triangle within a circle.
class check
{
public static void main(String args[])
{
int no = Integer.parseInt(args[0]);
int n = no;
int rev=0,rem;
while(no > 0)
{
rem = no % 10;
rev = rev * 10 + rem;
no = no / 10;
}
if(rev == n)
{
System.out.println(n+" is a Palindrome Number");
}
else
{
System.out.println(n+" is not a Palindrome Number");
}
}
}
10.
Write Program to accept names of employee and their salary. Sort the record in descending order based on their salary.
import java.util.Scanner;
class descsort
{
public static void main(String args[])
{
Scanner s = new Scanner(System.in);
System.out.println("How many Employee Insert:-");
int n;
n = s.nextInt();
int no[] = new int[n];
String name[] = new String[n];
System.out.println("\n");
for(int i=0;i<n;i++)
{
System.out.print("Enter the Employee Name "+(i+1)+":");
name[i] = s.next();
System.out.print("Enter the Employee Salary "+(i+1)+":");
no[i] = s.nextInt();
System.out.println("\n");
}
System.out.println("________________List of Employee____________");
for(int i=0;i<n;i++)
{
System.out.println("Enter the Employee No"+(i+1)+":"+no[i]);
System.out.println("Enter the Employee Name"+(i+1)+":"+name[i]);
System.out.println("________________");
}
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
if(no[i]<no[j])
{
int t = no[i];
no[i] = no[j];
no[j] = t;
String temp = name[i];
name[i] = name[j];
name[j] = temp;
}
}
}
System.out.println("\n");
System.out.println("___________________Sorting________________");
for(int i=0;i<n;i++)
{
System.out.println("Enter the Employee No"+(i+1)+":"+no[i]);
System.out.println("Enter the Employee Name"+(i+1)+":"+name[i]);
System.out.println("______________");
}
}
}
11.
Write an Application that creates and start three threads. Each thread is instantiated from the same class. It executes a loop with 10 iteration. Each iteration displays the character 'A' and sleep between 300 to 500 millisecond. The application waits for all the thread to complete and then display a message.
"Within 3 Days"
"After Exam OR Within 3 Day"
"After Exam OR Within 3 Day"
Write Program to Applet a User input two value and get the Sum of two value.
"After Exam OR Within 3 Day"
Write Program to Applet which Display the triangle within a circle.
"After Exam OR Within 3 Day"
Comment Here