Today I Would like write an article about Java Basic Programs here you have find some programs start with basic and also implement large programs.Every Programing tells how to write java code. java is case sensitive language concentrate on writing class name and main method and body in the program.
Logical Programs In Java
1.Write a program To Print" HELLO WORLD "in Java?
class Hello
{
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}
2.Write a program to addition of two numbers in java?
import java.util.*;
class Add
{
public static void main(String[] args)
{
int a,b,c;
Scanner s=new Scanner(System.in);
System.out.println("enter a,b values:");
a=s.nextInt();
b=s.nextInt();
c=a+b;
System.out.println("the sum is"+c);
}
}
(or)
class Addition
{
public static void main(String[] args)
{
int a=5,b=15,c;
c=a+b;
System.out.println(c);
}
}
3.Write a program for Array Index Out Of Bounds Exception in Java?
class Arg
{
public static void main(String args[])
{
try
{
System.out.println(args[0]);
}
catch (Exception e)
{
System.out.println(e);
}
}
}
4.Check whether given Number is Armstrong or Not in Java?
import java.util.*;
class Armstrong
{
public static void main(String[] args)
{
int m,n,r,sum=0;
System.out.println("enter n val");
Scanner s=new Scanner(System.in);
n=s.nextInt();
m=n;
while(m>=1)
{
r=m%10;
sum=sum+r*r*r;
m=m/10;
}
if(sum==n)
System.out.println("armstrong");
else
System.out.println("not armstrong");
}
}
5.Program Ascii Value increamentation?
class Ascii
{
public static void main(String[] args)
{
char c='A';
System.out.println(c);
c++;
System.out.println(c);
}
}
o/p:
A
B
6.program for Date Display?
import java.util.*;
class Date
{
public static void main(String[] args)
{
Date d=new Date();
System.out.println(d);
}
}
7.Write a program print the Numbers in any Range?
import java.util.*;
class Format
{
public static void main(String[] args)
{int n,k;
System.out.println("enter the range");
Scanner s=new Scanner(System.in);
n=s.nextInt();
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{k=i;
System.out.print(k);
k++;
}
System.out.println();
}
}
}
8.Write a program for checking greater number in given numbers?
class Greater
{
public static void main(String[] args)
{
int a=20,b=30,e=40,f=50;
boolean c=a>b;
boolean d=e>=f;
if(c)
{
System.out.println(a+">"+b);
}
else
{
System.out.println(a+"<"+b);
}
if(d)
{
System.out.println(e+">="+f);
}
else
{
System.out.println(e+"<="+f);
}
}
}
Friends today I start to write java programs for java learners .so,please concentrate on Java Programs and also Share this to your Friends Through Facebook,Twitter,Google+ .Do have any ideas are complaints please comment ,thank you friends.
0 comments:
Post a Comment