Java Programs
Java Programs
1) Simple.java =>
public class Simple {
2) Reverse.java =>
/*(Practical Question) Write a Java Program to Reverse a
Number. Accept number using command line argument. */
4) ArrayDemo.java =>
public class ArrayDemo {
5) Addition.java
/* (Practical Question)
* Write a Java program to print the sum of elements of
the array.
* Also display array elements in ascending order */
//sorting array
for(i=0;i<num.length;i++)
{
for(j=i+1;j<num.length;j++)
{
if(num[i]>num[j])
{
int temp=num[i];
num[i]=num[j];
num[j]=temp;
}
}
}
6) MultiTable.java =>
/* (Practical Question) Write a Java program to accept a
number from command prompt
* and generate multiplication table of a number.
* Accept number using BufferedReader class.*/
import java.io.*;
7) MyNumber.java =>
/* (Practical Question) Define a class MyNumber having one
private integer data member.
* Write a default constructor initialize it to 0 and
another constructor to initialize it to a value.
* Write methods isNegative, isPositive, isOdd, iseven.
* Use command line argument to pass a value to the object
and perform the above tests. */
8) Employee.java
/*(Practical Question) Write a java program which define
class Employee with data member as name and salary.
* program store the information of 5 Employees.
* display the name who earn maximum salary.(Use arrary of
object)*/
import java.util.*;
String name;
void input() {
name=sc.next();
salary=sc.nextFloat();
void show() {
System.out.println("Salary is :"+salary);
for(int i=0;i<5;i++)
{
e[i]=new Employee();
e[i].input();
sal[i]=e[i].salary;
for(int i=0;i<5;i++)
{
e[i].show();
float max=sal[0];
int j=0;
for(int i=0;i<5;i++)
{
if(max<sal[i])
{
max=sal[i];
j=i;
}
}
System.out.println("\n\n
***********Employee Having Maximum Salary************");
e[j].show();