Search This Blog

If you have any problem or question please write in the comments. We will try to solve and send you the solution. Not just that we will also post your problems solution on our blog.

Friday, 8 April 2011

A simple Java program which tells the weather

import java.util.*;
class weather
{
public static void main (String arg[])
{
Scanner in=new Scanner (System.in);
int a;
System.out.print ("\n\t Enter the temprature in Celcious = ");
a=in.nextInt();
if (a<=20)
System.out.print ("\n\t Whether is Cool ");
else if (a<=30 && a>=21)
System.out.println ("\n\t Whether is Fine ");
else if (a<=40 && a>=31)
System.out.println ("\n\t Whether is Hot ");
else 
System.out.println ("\n\t Whether is very Hot ");
}
}

Java program to find whether the given number is prime or not

import java.util.*;
class prime
{
public static void main (String arg[])
{
Scanner in=new Scanner (System.in);
int a,b=2,c=1,d;
System.out.print ("\n\t Enter first number = ");
a=in.nextInt();
System.out.print ("\n\t Enter second number = ");
d=in.nextInt();
a+=d;
System.out.println ("\n\t Sum of the numbers = "+a);
while (b<=a/2)
{
if (a%b==0)
c=0;
++b;
}
if (c==0)
System.out.println ("\n\t Sum of the numbers 
is Not a prime number ");
else 
System.out.println ("\n\t Sum of the numbers 
is Prime number ");
}
}

Java program to find out grade of a student

import java.util.*;
class marksgrade
{
public static void main (String arg[])
{
Scanner in=new Scanner (System.in);
int a,b;
System.out.print ("\n\t Enter your total marks = ");
a=in.nextInt();
System.out.print ("\n\t Enter obtained marks = ");
b=in.nextInt();
float p=(b*100)/a;
System.out.println ("\n\t Percentage = "+p);
if (p>=90)
System.out.println ("\n\t Grade A ");
else if (p>=80 && p<=89)
System.out.println ("\n\t Grade B+");
else if (p>=70 && p<=79)
System.out.println ("\n\t Grade B ");
else if (p>=50 && p<=69)
System.out.println ("\n\t Grade C ");
else 
System.out.println ("\n\t Fail ");
}
}

A simple Java program which tells about colours

import java.util.*;
class colours
{
public static void main (String arg[])
{
Scanner in=new Scanner (System.in);
int a;
System.out.println ("\n\t The number should be from 12 to 23 ");
System.out.print ("\n\t Enter the number = ");
a=in.nextInt();
if (a==12 || a==13 || a==14)
System.out.println ("\n\t Red Colour ");
else if (a==15 || a==16 || a==17)
System.out.println ("\n\t Black Colour ");
else if (a==18 || a==19 || a==20)
System.out.println ("\n\t Blue Colour ");
else if (a==21 || a==22 || a==23)
System.out.println ("\n\t White Colour ");
else 
System.out.println ("\n\t Out of defined range ");
}
}

Thursday, 7 April 2011

Java program to find that the given number (from 14-38) is divisible by 3 or not

import java.util.*;
class p2
{
public static void main (String arg[])
{
Scanner in=new Scanner (System.in);
int a=1,b;
System.out.println ("\n\t The number should be from 14 to 38");
System.out.print ("\n\t Enter the number = ");
a=in.nextInt();
if (a>=14 && a<=38)
{
b=a%3;
if (b==0)
System.out.println ("\n\t Divisible by 3 ");
else
System.out.println ("\n\t Not Divisible by 3 ");
}
else
System.out.println ("\n\t Out of defined range ");

}

}

Java program to calculate salary of a employe

import java.util.*;
class p1
{
public static void main (String arg[])
{
Scanner in=new Scanner (System.in);
int s,s1=1,e,t=0;
System.out.print ("\n\t Enter total number of Employes = ");
e=in.nextInt();
int a=e;
while (s1<=e)
{
System.out.print ("\n\t Enter salary of Employe no "+s1+" = ");
s=in.nextInt();
t+=s;
++s1;
}
float avg=t/a;
if (avg<60)
System.out.println ("\n\t Good ");
else
System.out.println ("\n\t Fair ");
}
}

Java program for ASCII values

import java.util.*;
class ascii
{
public static void main (String arg[])
throws java.io.IOException
{
int b;
char a;
Scanner in=new Scanner (System.in);
System.out.print ("\n\t Enter a character = ");
a=(char) System.in.read();
b=(int)a;
System.out.println ("\n\t The ASCII value of "+a+" is = "+b);
}
}