Sunday, 5 October 2014
java program to accept company name and size of screen and display it for 5 objects
import java.io.*;
import java.lang.*;
class mobile
{
String cname;
float size;
void accept()
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
try
{
System.out.print("\n\n\t\tEnter the Company name = ");
cname=br.readLine();
System.out.print("\n\n\t\tEnter the size of Screen = ");
size=Float.parseFloat(br.readLine());
}
catch(IOException e)
{
// System.out.print("\n\n\t\tI/O Error");
}
}
void display()
{
System.out.print("\n\n\t\t=======================================");
System.out.print("\n\n\t\tThe Company Name is = "+cname);
System.out.print("\n\n\t\t========================================");
System.out.print("\n\n\t\tThe Screen Size is = "+size);
}
public static void main(String args[])throws IOException
{
int i;
mobile m[]=new mobile[5];
for(i=0;i<5;i++) { m[i]=new mobile(); m[i].accept(); } for(i=0;i<5;i++) { m[i].display(); } } } OUTPUT : -
java program to display the name of company having more employees. Consider 4 Companies
class emp
{
public static void main(String args[])
{
String n1,n2,n3,n4;
int e1,e2,e3,e4;
n1="Nokia";
e1=2000;
n2="Samsung";
e2=20000;
n3="Micromax";
e3=4000;
n4="Micromax";
e4=50000;
System.out.print(“\n\n\t\t~~~~~~~~~~~~~~~~~~~~~~~”);
System.out.print("\n\n\t\tThe Company having more Emplyees");
System.out.print(“\n\n\t\t~~~~~~~~~~~~~~~~~~~~~~”);
if(e1>e2 && e1>e3 && e1>e4)
{
System.out.print("\n\n\t\tName of Company = "+n1);
System.out.print(“\n\n\t\t~~~~~~~~~~~~~~~~~~~~”);
System.out.print("\n\n\t\tTotal Employees = "+e1);
System.out.print(“\n\n\t\t~~~~~~~~~~~~~~~~~~~~”);
}
if(e2>e3 && e2>e1 && e2>e4)
{
System.out.print("\n\n\t\tName of Company = "+n2);
System.out.print(“\n\n\t\t~~~~~~~~~~~~~~~~~~~~”);
System.out.print("\n\n\t\tTotal Employees = "+e2);
System.out.print(“\n\n\t\t~~~~~~~~~~~~~~~~~~~~”);
}
if(e3>e1 && e3>e2 && e3>e4)
{
System.out.print("\n\n\t\tName of Company = "+n3);
System.out.print(“\n\n\t\t~~~~~~~~~~~~~~~~~~~~”);
System.out.print("\n\n\t\tTotal Employees = "+e3);
System.out.print(“\n\n\t\t~~~~~~~~~~~~~~~~~~~~~”);
}
if(e4>e1 && e4>e2 && e4>e3)
{
System.out.print("\n\n\t\tName of Company = "+n4);
System.out.print(“\n\n\t\t~~~~~~~~~~~~~~~~~~~~~”);
System.out.print("\n\n\t\tTotal Employees = "+e4);
System.out.print(“\n\n\t\t~~~~~~~~~~~~~~~~~~~~~”);
}
}
}
OUTPTUT : -
java program to find first 7 terms of fibonnaci series
class fibo
{
public static void main(String args[])
{
int a=1,b=1,c=0;
System.out.print("\n\n\t\t===============================");
System.out.print("\n\n\t\tFirst 7 terms of Fibonacci series are ");
System.out.print("\n\n\t\t===============================");
System.out.print("\n\n\t\t"+a+" "+b);
for(int i=3;i<=7;i++) { c=a+b; System.out.print(" "+c); a=b; b=c; } System.out.print("\n\n\t\t==============================="); } } OUTPUT : -
Saturday, 4 October 2014
program in java to find multiples of 5 in the range of 20 to 70
class five
{
public static void main(String args[])
{
int i=20;
while(i<=70) { System.out.print("\n\n\t\tThe multiple is = "+i); i=i+5; } } }
java program to add two numbers if both numbers are greater than 10 designed by pratik
class myadd
{
public static void main(String args[])
{
int num1=20,num2=40,add;
if(num1>10 && num2>10)
{
add=num1+num2;
System.out.print("\n\n\t\tThe Addition is = "+add);
}
}
}
program in java to display the name of player who played highest matches designed by pratik
class players
{
public static void main(String args[])
{
String n1,n2,n3,n4;
int m1,m2,m3,m4;
n1="Pratik";
m1=11;
n2="Savita";
m2=36;
n3="Abhishek";
m3=40;
System.out.print("\n\n\t\t~~~~~~~~~~~~~~~~~~~~");
System.out.print("\n\n\t\t~~~~~~~~~~~~~~~~~~~~");
System.out.print("\n\n\t\t~~~~~~~~~~~~~~~~~~~~");
if(m1>m2 && m1>m3)
{
System.out.print("\n\n\t\tName is = "+n1);
System.out.print("\n\n\t\t~~~~~~~~~~~~~~~~~~~~");
System.out.print("\n\n\t\tMatches Played = "+m1);
System.out.print("\n\n\t\t~~~~~~~~~~~~~~~~~~~~");
}
if(m2>m3 && m2>m1)
{
System.out.print("\n\n\t\tName is = "+n2);
System.out.print("\n\n\t\t~~~~~~~~~~~~~~~~~~~~");
System.out.print("\n\n\t\tMatches Played = "+m2);
System.out.print("\n\n\t\t~~~~~~~~~~~~~~~~~~~~");
}
if(m3>m1 && m3>m2)
{
System.out.print("\n\n\t\tName is = "+n3);
System.out.print("\n\n\t\t~~~~~~~~~~~~~~~~~~~~");
System.out.print("\n\n\t\tMatches Played = "+m3);
System.out.print("\n\n\t\t~~~~~~~~~~~~~~~~~~~~");
}
}
}
OUTPUT : -
program in java using “ print ” and “ println " designed by pratik
Program using “ print ” and “ println"
class sample
{
public static void main(String args[])
{
System.out.print("\n\n\t\tWelcome");
System.out.print("\n\n\t\tTo");
System.out.println("\n\n\t\tJava");
System.out.println("\n\n\t\tProgramming");
}
}
OUTPUT : -
Subscribe to:
Posts (Atom)