0% found this document useful (0 votes)
25 views9 pages

JAVAprgm Output

Uploaded by

SAFA's Creation
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views9 pages

JAVAprgm Output

Uploaded by

SAFA's Creation
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 9

/* PROGRAM TO IMPLEMENT SIMPLE MATHEMATICAL FUNCTION */

class MathFunction
{
public static void main(String args[])
{
double x;
System.out.println("\nSIMPLE MATHEMATICAL FUNCTIONS");
System.out.println("*~*~*~*~*~*~*~*~*~*~*~*~*~*~*");
x=Math.max(10,5);
System.out.println("maximum value of 10 & 5 is :\t"+x);
x=Math.min(10,6);
System.out.println("minimum value of 10 & 6 is :\t"+x);
x=Math.sqrt(5);
System.out.println("square root value of 5 is :\t"+x);
x=Math.log(3);
System.out.println("logarithmic value of 3 is :\t"+x);
x=Math.pow(4,3);
System.out.println("power value of 4 and 3 is :\t"+x);
}
}
OUTPUT:
C:\javapgms>javac MathFunction.java
C:\javapgms>java MathFunction

SIMPLE MATHEMATICAL FUNCTIONS


*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
maximum value of 10 & 5 is : 10.0
minimum value of 10 & 6 is : 6.0
square root value of 5 is : 2.23606797749979
logarithmic value of 3 is : 1.0986122886681098
power value of 4 and 3 is : 64.0
/* PROGRAM TO IMPLEMENT MULTIPLICATION TABLE IN A MATRIX FORAMT */

class MulTable
{
public static void main(String args[])
{
int i,j;
int a[][]=new int[10][10];
System.out.println("\n\nMULTIPLICATION TABLE IN MATRIX FORAMT");
System.out.println("*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*");
for(i=1;1<=10;i++)
{
for(j=1;j<=10;j++)
{
a[i-1][j-1]=i*j;
System.out.print(a[i-1][j-1]+"\t");
}
System.out.print("\n");
}
}
}
OUTPUT:

C:\javapgms>javac MulTable.java
C:\javapgms>java MulTable

MULTIPLICATION TABLE IN A MATRIX FORMAT


*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
1 2 3 4 5 6 7 8 9 10
2 4 6 8 10 12 14 16 18 20
3 6 9 12 15 18 21 24 27 30
4 8 12 16 20 24 28 32 36 40
5 10 15 20 25 30 35 40 45 50
6 12 18 24 30 36 42 48 54 60
7 14 21 28 35 42 49 56 63 70
8 16 24 32 40 48 56 64 72 80
9 18 27 36 45 54 63 72 81 90
10 20 30 40 50 60 70 80 90 100
/* PROGRAM TO GENERATE RANDOM NUMBERS */

import java.util.Scanner;
import java.util.Random;
public class RandomNUM
{
public static void main(String[] input)
{
int len,i,randnum;
Random rn = new Random();
Scanner scan = new Scanner(System.in);
System.out.print("How Many Random Numbers You want to Generate ? ");
len = scan.nextInt();
System.out.println("\nGenerating " + len + " Random Numbers in the range 0...999");
for(i=0; i<len; i++)
{
randnum = rn.nextInt(200);
System.out.print(randnum + "\n");
}
}
}

OUTPUT: 1
C:\javapgms>javac RandomNUM.java

C:\javapgms>java RandomNUM

How Many Random Numbers You want to Generate ? 5

Generating 5 Random Numbers in the range 0...999


115
111
127
73
155

OUTPUT: 2

C:\javapgms>javac RandomNUM.java

C:\javapgms>java RandomNUM

How Many Random Numbers You want to Generate ? 10

Generating 10 Random Numbers in the range 0...999


69
82
22
5
182
177
78
75
37

/* PROGRAM TO SORT NAMES IN ALPHABETICAL ORDER */


import java.util.Scanner;
public class Alphabetical_Order
{
public static void main(String[] args)
{
int n;
String temp;
Scanner s = new Scanner(System.in);
System.out.println("\n\nSORTING NAMES IN ALPHABETICAL ORDER");
System.out.println("*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*");
System.out.print("\nEnter number of names you want to enter:");
n = s.nextInt();
String names[] = new String[n];
Scanner s1 = new Scanner(System.in);
System.out.println("\nEnter all the names:");
for(int i = 0; i < n; i++)
{
names[i] = s1.nextLine();
}
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
if (names[i].compareTo(names[j])>0)
{
temp = names[i];
names[i] = names[j];
names[j] = temp;
}
}
}
System.out.println("\nNAMES IN SORTED ORDER:");
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~");
for (int i = 0; i < n - 1; i++)
{
System.out.print(names[i] + "\n");
}
System.out.print(names[n - 1]);
}
}

OUTPUT:
C:\javapgms>javac Alphabetical_Order.java

C:\javapgms>java Alphabetical_Order

SORTING NAMES IN ALPHABETICAL ORDER


*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*

Enter number of names you want to enter:5

Enter all the names:


Jasima
Ilakkiya
Asmath
Nilofar
Janani
NAMES IN SORTED ORDER:
~~~~~~~~~~~~~~~~~~~~~~~
Asmath
Ilakkiya
Jasima
Janani
Nilofar

/* SIMPLE VECTOR PROGRAM TO GET THE ELEMENTS */

import java.util.Iterator;
import java.util.Vector;

public class SimpleVector


{
public static void main(String[] args) {
Vector v = new Vector();
v.add("1");
v.add("2");
v.add("3");
System.out.println("\nGetting elements of Vector:");
System.out.println("*~*~*~*~*~*~*~*~*~*~*");
System.out.println(v.get(0));
System.out.println(v.get(1));
System.out.println(v.get(2));
}
}

OUTPUT:

C:\javapgms>javac SimpleVector.java
C:\javapgms>java SimpleVector

Getting elements of Vector:


*~*~*~*~*~*~*~*~*~*~*
1
2
3

You might also like