Java
Java Programming
Import
java.io*;
Class Hello
{
Public
static void main (String args[])
{
System.out.println(“Hello
My First Java programming”);
}
}
Java programming used few common words meaning
Used Word in Java
|
Meaning of Word and use’s
|
Import
|
Used
for import of file
|
Java
|
Programming
Name
|
Io
|
In
and out data in Java
|
Class
|
Object
|
Hello
|
Name
|
Public
|
Accessible
any ware
|
Static
|
Keyword
|
Void
|
Keyword
, Not Return Value
|
String
|
Used
for text pass the string value like:
Hello My First Java programming
|
Main
|
Object
, Program starting to execution
|
Args[]
|
Pass
argument in java
|
System.out.println
|
Print
output in given block
|
through
io exception
|
Any
exception showing
|
Output = Hello
My First Java programming
2) Write a
program in adding two words in Java?
Import Java
.io.*;
Class
addword
{
Public
static void main(String args[]) throws IOException
{
InputStreamReader
in =new InputStreamReader (System.in);
Int a,b,c;
System.out.println(“Enter
the First Value:”);
a=Integer.ParseInt(br.readLine();
System.out.printLn(“Enter
the Second Value:”);
b=Integer.ParseInt(br.readLine();
c=a+b;
System.out.println(“Sum
of Total=”+c);
}
}
Input
|
Output
|
Enter
the First Value : 10
Enter
the Second Value:20
|
Sum
of Total= 30
|
3) Write a program and calculate area
in Java?
import
java.io.*;
class
area;
{
public
static void main (String args[]) throws IOE xception
{
InputStreamReader
in=new InputStreamReader(System.in);
BufferedReader
br=new BufferedReader(in);
Int
l,b,m;
System.out.Println(“Enter
The Length of Area:”);
l=Integer.ParseInt(br.readLine()); // used for reading of line
System.out.Println(“Enter
The Breath of Area:”);
b=Integer.ParseInt(br.readLine());
m=l*b;
System.out.Println(“Area=”+m);
}
}
Input
|
Output
|
Enter The Length of Area: 20
Enter The Breath of Area:20
|
Area= 400
|
4) Write a program of Circle in Java?
import
java.io.*;
Class
circle
{
Public
static void main(String args[]) throws IOException
{
InputStreamReader
in=new InputStreamReader(System.in)
BufferedReader
br=new BufferedReader(in);
Int
a,o;
System.out.println(“Enter
the Area:”);
a=Integer.ParseInt(br.readLine());
o=a*2;
System.out.println(“Total
Area=”+o);
}
}
Input
|
Output
|
Enter the Area: 20
|
Total Area= 40
|
5) Write a program to find out total and average marks of student who has appearing in examination.
import
java.io.*;
Class
student
{
Public
static void main (String args[])throws IOException
{
inputStreamReader
in=new InputStreamReader(System.in)
int
m,n,o,p,q,r,s; // Local Variable
System.out.println(“Enter
The Marks of Math:”);
m=Integer.Parse.Int(br.readLine());
System.out.println(“Enter
The Marks of English:”);
n=Integer.Parse.Int(br.readLine());
System.out.println(“Enter
The Marks of Science:”);
o=Integer.Parse.Int(br.readLine());
System.out.println(“Enter
The Marks of S.Science:”);
p=Integer.Parse.Int(br.readLine());
q=m+n+o+p;
system.out.println(“Total
Marks of Student=”+q);
r=q/4;
System.out.println(Average
Marks of Student=”+r);
}
}
Input
|
Output
|
Enter The Marks of
Math: 70
Enter The Marks of English:60
Enter The Marks of
Science:80
Enter The Marks of S.
Science:90
|
Total Marks of
Student= 300
Average Marks of
Student= 75
|
6) Write a program if a person goes to
bank for withdrawn certain amount of money. If the bank given change in ` 2000 Note
and Rs 100 find out how many Rs 2000 note and how many Rs100 note the person received.
import
java.io.*;
Class
BankMoney
{
Public
static void main(String arge[])throws IOException
{
BufferedReader
br=new BufferedReader(System.in);
Int
a,b,c,d,e;
System.out.Println(“Enter
The Amount:”);
a=Integer.Parse.Int(br.readLine());
b=a/2000;
c=a%2000;
d=a/100;
e=a%100;
System.out.Println(“Number
of 2000 `=+b);
System.out.Println(“Number
of 100 `=+d);
}
}
Input
|
Output
|
Enter The Amount:
2500
|
Number of 2000 Rs = 1
Number of 100 Rs = 5
|
7) Write a program to generate natural number in Java?
import.java.io.*;
class
number
{
Public
static void main (String args[])throws IOException
{
BufferedReader
br=new BufferedReader(new InputStreamReader(System.in));
Int
m;
For(m=1;
m=<11;m++)
{
System.out.println(“m+”,”);
}
}
Output:
1,2,3,4,5,6,7,8,9,10.
Looping in Java
8)Write a program in Java and generate
odd number between 50 to 100.
import.java.io.*;
Class
natural
{
Public
static void main (String args[])throws IOException
{
BufferedReader
br=new BufferedReader(new ImputStreamReader(System.in));
Int
n;
for(n=49;n<=51*2;n++)
if(n%2!=0)
{
System.out.println(n+””);
}
}
}
9) Write a program to generate even number between 200 to 80.
9) Write a program to generate even number between 200 to 80.
import
java.io.*;
class
evennum
{
Public
static void main(String args[])throws IOException
{
BufferedReader
br=new BufferedReader(new ImputStreamReader(System.in));
Int
m;
for(m=80;m<=101*2;m++)
// if number is not divided by 2 it means it’s even number.
if(m%2==0)
{
System.out.println(m+””);
}
}
}
10) Write a program to generate natural number Up to n?
10) Write a program to generate natural number Up to n?
import
java.io.*;
class
nnumber
{
Public
static void main(String args[])throws IOException
{
BufferedReader
br=new BufferedReader(new ImputStreamReader(System.in));
Int
p,q; //p is looping variable and q for sorting data.
for(q=1;q<=p;q++)
{
System.out.println(q);
}
}
}
11) Write a program to generate natural numbers between given range?
11) Write a program to generate natural numbers between given range?
import
java.io.*;
class
rangenum
{
Public
static void main(String args[])throws IOException
{
BufferedReader
br=new BufferedReader(new ImputStreamReader(System.in));
Int
a,b,c;
System.print.out.ln(“Enter
The First Number of Range:”);
a=integer.parse.Int(br.readLine());
System.print.out.ln(“Enter
The Second Number of Range:”);
b=integer.parse.Int(br.readLine());
for
(c=a; c<=b; c++ )
{
System.out.println(c);
}
}
}
Input
|
Output
|
Enter The First
Number of Range: 1
Enter The Second
Number of Range:4
|
1,2,3,4
|
12) Write a program to print your name 4 times?
import
java.io.*;
class
rangenum
{
Public
static void main(String args[])throws IOException
{
BufferedReader
br=new BufferedReader(new ImputStreamReader(System.in));
Int
x ;
for
(x=1;x<=5;x++ )
{
System.out.println(x+”Kumar”);
}
}
}
Output:
Kumar, Kumar, Kumar, Kumar, Kumar
Comments
Post a Comment