Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
4 views

Java Print

Uploaded by

Arti Kumari
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Java Print

Uploaded by

Arti Kumari
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Fibonacci series

public class Fibonacci


{
public static void main(String args[])
{
int n1=0,n2=1,n3,i,count=10;
System.out.print(n1+" "+n2); //print 0 and 1
for(i=2;i<count;++i)//loop starts from 2
{
n3=n1+n2;
System.out.print(" "+n3);
n1=n2;
n2=n3;
}
}
}

Output:

0 1 1 2 3 5 8 13 21 34

1
Prime Number Program
public class Prime
{
public static void main(String args[])
{
int i,m=0,flag=0;
int n=3; // number to be checked
m=n/2;
if(n==0||n==1)
{
System.out.println(n+" is not prime number");
}
else
{
for(i=2;i<=m;i++){
if(n%i==0)
{
System.out.println(n+" is not prime number");
flag=1;
break;
} }
if(flag==0) { System.out.println(n+" is prime
number"); }
}} }
Output: 3 is prime number

2
Palindrome Program
public class Palindrome
{
public static void main(String args[])
{
int r,sum=0,temp;
int n=454;//number checked for palindrome
temp=n;
while(n>0)
{
r=n%10; //getting remainder
sum=(sum*10)+r;
n=n/10;
}
if(temp==sum)
System.out.println("palindrome number ");
else
System.out.println("not palindrome");
}
}
Output:palindrome number

3
Armstrong Number
public class Armstrong
{
public static void main(String[] args)
{
int c=0,a,temp;
int n=153;// number to check
temp=n;
while(n>0)
{
a=n%10;
n=n/10;
c=c+(a*a*a); }
if(temp==c)
System.out.println("Armstrong no.");
else
System.out.println("Not armstrong");
} }
Output:Armstrong no.

4
Find Largest Number in an Array
public class LArray
{
public static int getLargest(int[] a, int
total)
{
int temp;
for (int i = 0; i < total; i++)
{
for (int j = i + 1; j < total; j++)
{
if (a[i] > a[j])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
return a[total-1];
}
public static void main(String args[])

5
{
int a[]={1,2,5,6,3,2};
int b[]={44,66,99,77,33,22,55};
System.out.println("Largest:
"+getLargest(a));
System.out.println("Largest:
"+getLargest(b));
}}

Output:

Largest: 6
Largest: 99

6
String
public class StringExample
{ public static void main(String[] args)
{ String s1 = "Computer Science";
String s2 = s1 +" ";
String s3 = s2.substring(10,17);
String s4 = "is fun";
String s5 = s2 + s4;
System.out.println("s1: " + s1);
System.out.println("s2: " + s2);
System.out.println("s3: " + s3);
System.out.println("s4: " + s4);
System.out.println("s5: " + s5);
}}

7
Taking Input from user
import java.util.Scanner;

public class ScannerAndKeyboard


{
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
System.out.print( "Enter your name: " );
String name = s.nextLine();
System.out.println( "Hello " + name + "!" );
}
}

8
Hyperlink in HTML
<html>
<body>
<a href=" http://www.rsmt.ac.in/ ">RSMT</a>
</body>
</html>

9
Adding Image in HTML
<html>
<body>
<img src="rsmt.jpg" width="300"
height="200">
</body>
</html>

10
Heading Tag In HTML
<html>
<body>
<h1>Ajay 1</h1>
<h2>Ajay 2</h2>
<h3>Ajay 3</h3>
<h4>Ajay 4</h4>
<h5>Ajay 5</h5>
<h6>Ajay 6</h6>
</body>
</html>

11
Font Tag & Background Image
in HTML
<html>
<body background="rose.jpg">
<marquee behavior=alternate>
<font color="red" size=7> ARTI...
</font>
</body>
</html>

12
Creating Table in HTML
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
}
</style>
</head>
<body>

<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Ajay</td>
<td>Gupta</td>
<td>21</td>
13
</tr>
<tr>
<td>Arti</td>
<td>Gupta</td>
<td>23</td>
</tr>
<tr>
<td>jay</td>
<td>kumar</td>
<td>01</td>
</tr>
</table>

</body>
</html>

14
List in HTML
<html>
<body>
<h2>Unordered List with Disc Bullets</h2>
<ul style="list-style-type:disc">
<li>Ajay</li>
<li>Arti</li>
<li>jay</li>
</ul>
<h2>Ordered List with Numbers</h2>
<ol type="1">
<li>Ajay</li>
<li>Arti</li>
<li>jay</li>
</ol>
<h2>Ordered List with Letters</h2>
<ol type="A">
<li>Ajay</li>
<li>Arti</li>
<li>jay</li>
</ol>

</body>
</html>
15
16

You might also like