This is a small blog for programming.I want to share my thinking,creation and learning to all of you.I also want to develop my own skill as well as yours.
Monday, October 19, 2015
Tuesday, June 9, 2015
Print Fibonacci Series In Java
Program:
package beforeburn;
import java.util.Scanner;
public class Practice1 {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("Enter the limit of the fibonacci series:");
int userInput = sc.nextInt();
int variable1=1;
int variable2=0;
int fibonacciResult=0;
System.out.println("Finally the fibonacci series is:");
for (int point=0; point<=userInput;point++) {
System.out.print(fibonacciResult+" ");
fibonacciResult=variable1+variable2;
variable1=variable2;
variable2=fibonacciResult;
}
}
}
Output:
Enter the limit of the fibonacci series:
10
Finally the fibonacci series is:
0 1 1 2 3 5 8 13 21 34 55
package beforeburn;
import java.util.Scanner;
public class Practice1 {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("Enter the limit of the fibonacci series:");
int userInput = sc.nextInt();
int variable1=1;
int variable2=0;
int fibonacciResult=0;
System.out.println("Finally the fibonacci series is:");
for (int point=0; point<=userInput;point++) {
System.out.print(fibonacciResult+" ");
fibonacciResult=variable1+variable2;
variable1=variable2;
variable2=fibonacciResult;
}
}
}
Output:
Enter the limit of the fibonacci series:
10
Finally the fibonacci series is:
0 1 1 2 3 5 8 13 21 34 55
Screenshots
Program
Output
Friday, March 20, 2015
Print Pass Fail By Scanner And Continuous Using Method
Program:
package passfailproject;
import java.util.Scanner;
public class Checkpassfail {
static Scanner sc=new Scanner(System.in);
public static void main(String[] args) {
int inputMark;
System.out.println("Enter -1 to exit the program");
System.out.println("Enter Your mark that you have got");
inputMark=sc.nextInt();
while(inputMark!=-1){
yourresult(inputMark);
System.out.println("Enter your mark again");
inputMark=sc.nextInt();
}
System.out.println("You have exited the program");
}
static public void yourresult(int mark) {
if(mark<50){
System.out.println("You have Failed");
}else{
System.out.println("You Have Passed");
}
}
}
Output:
Enter -1 to exit the program
Enter Your mark that you have got
60
You Have Passed
Enter your mark again
56
You Have Passed
Enter your mark again
49
You have Failed
Enter your mark again
76
You Have Passed
Enter your mark again
-1
You have exited the program
package passfailproject;
import java.util.Scanner;
public class Checkpassfail {
static Scanner sc=new Scanner(System.in);
public static void main(String[] args) {
int inputMark;
System.out.println("Enter -1 to exit the program");
System.out.println("Enter Your mark that you have got");
inputMark=sc.nextInt();
while(inputMark!=-1){
yourresult(inputMark);
System.out.println("Enter your mark again");
inputMark=sc.nextInt();
}
System.out.println("You have exited the program");
}
static public void yourresult(int mark) {
if(mark<50){
System.out.println("You have Failed");
}else{
System.out.println("You Have Passed");
}
}
}
Output:
Enter -1 to exit the program
Enter Your mark that you have got
60
You Have Passed
Enter your mark again
56
You Have Passed
Enter your mark again
49
You have Failed
Enter your mark again
76
You Have Passed
Enter your mark again
-1
You have exited the program
Screenshots
Program
Output
Monday, March 2, 2015
Object and Classes::public,private,default,constructor method,instance method In Java
Program:
package newfifthlecture;
public class Learnnewclass {
public int aNewnumber=12;//example
static public Carclass myCar;//creating new object
static public Carclass myanothercarCar;//creating another new object
public static void main(String[] args) {
myCar=new Carclass();//calling
System.out.println("Car manufacturer name: "+ myCar.getManufacturerName());
myanothercarCar=new Carclass("TOYOTA","Corolla", 230);//calling and initialize
System.out.println("modelname of my car: "+myanothercarCar.modelName);
}
}
New class in same package:
package newfifthlecture;
public class Carclass {
private String manufacturerName;
public String modelName;
private double fuelAmount;
public Carclass() {
//constructor method
manufacturerName=new String();
modelName="Allion";
fuelAmount=30;
}
public Carclass(String manu,String model,double fuel) {
//another constructor method
manufacturerName=manu;
modelName=model;
fuelAmount=fuel;
}
public String getManufacturerName(){
// instance method
return manufacturerName;
}
}
Output:
Car manufacturer name:
modelname of my car: Corolla
package newfifthlecture;
public class Learnnewclass {
public int aNewnumber=12;//example
static public Carclass myCar;//creating new object
static public Carclass myanothercarCar;//creating another new object
public static void main(String[] args) {
myCar=new Carclass();//calling
System.out.println("Car manufacturer name: "+ myCar.getManufacturerName());
myanothercarCar=new Carclass("TOYOTA","Corolla", 230);//calling and initialize
System.out.println("modelname of my car: "+myanothercarCar.modelName);
}
}
New class in same package:
package newfifthlecture;
public class Carclass {
private String manufacturerName;
public String modelName;
private double fuelAmount;
public Carclass() {
//constructor method
manufacturerName=new String();
modelName="Allion";
fuelAmount=30;
}
public Carclass(String manu,String model,double fuel) {
//another constructor method
manufacturerName=manu;
modelName=model;
fuelAmount=fuel;
}
public String getManufacturerName(){
// instance method
return manufacturerName;
}
}
Output:
Car manufacturer name:
modelname of my car: Corolla
Screenshots
program 1:
program 2:
output
Sunday, March 1, 2015
Project Two for Java: Pascal's Triangle
Program:
package fourthlecture;
import java.util.Scanner;
public class Pascaltriangle {
static Scanner sc=new Scanner(System.in);
public static void main(String[] args) {
System.out.println("Enter -1 to exit ");
System.out.println("Please give a number which you convert pascal triangle: ");
int yourchoice=sc.nextInt();
while(yourchoice !=-1){
if(yourchoice <-1 || yourchoice>20){
System.out.println("Please input a value between 1~20 ");
yourchoice=sc.nextInt();
continue;
}
pascaltrianglee(yourchoice);
System.out.println("\n\n");
System.out.println("Please input a value between 1~20 ");
yourchoice=sc.nextInt();
}
System.out.println("You have exited the program.");
}
static void pascaltrianglee(int length){
int[][] pascal = new int[length][length];
for(int i=0;i<length;i++){
pascal[0][i]=1;
pascal[i][0]=1;
}
for(int row=1;row<length;row++){
for(int column=1;column<length-row;column++){
pascal[row][column]=pascal[row][column-1]+pascal[row-1][column];
}
}
for(int row=0;row<length;row++){
for(int column=0;column<length-row;column++){
System.out.print(pascal[row][column]+"\t");
}
System.out.println("\n");
}
}
}
Output:
Enter -1 to exit
Please give a number which you convert pascal triangle:
5
1 1 1 1 1
1 2 3 4
1 3 6
1 4
1
Please input a value between 1~20
6
1 1 1 1 1 1
1 2 3 4 5
1 3 6 10
1 4 10
1 5
1
Please input a value between 1~20
-1
You have exited the program.
package fourthlecture;
import java.util.Scanner;
public class Pascaltriangle {
static Scanner sc=new Scanner(System.in);
public static void main(String[] args) {
System.out.println("Enter -1 to exit ");
System.out.println("Please give a number which you convert pascal triangle: ");
int yourchoice=sc.nextInt();
while(yourchoice !=-1){
if(yourchoice <-1 || yourchoice>20){
System.out.println("Please input a value between 1~20 ");
yourchoice=sc.nextInt();
continue;
}
pascaltrianglee(yourchoice);
System.out.println("\n\n");
System.out.println("Please input a value between 1~20 ");
yourchoice=sc.nextInt();
}
System.out.println("You have exited the program.");
}
static void pascaltrianglee(int length){
int[][] pascal = new int[length][length];
for(int i=0;i<length;i++){
pascal[0][i]=1;
pascal[i][0]=1;
}
for(int row=1;row<length;row++){
for(int column=1;column<length-row;column++){
pascal[row][column]=pascal[row][column-1]+pascal[row-1][column];
}
}
for(int row=0;row<length;row++){
for(int column=0;column<length-row;column++){
System.out.print(pascal[row][column]+"\t");
}
System.out.println("\n");
}
}
}
Output:
Enter -1 to exit
Please give a number which you convert pascal triangle:
5
1 1 1 1 1
1 2 3 4
1 3 6
1 4
1
Please input a value between 1~20
6
1 1 1 1 1 1
1 2 3 4 5
1 3 6 10
1 4 10
1 5
1
Please input a value between 1~20
-1
You have exited the program.
Screenshots
program 1
Program:2
Output
Wednesday, February 25, 2015
Project One for Java : Bookstore For Purchase Book By Perchase
Program:
package firstclass;
import java.util.Scanner;
public class Bookstor {
static Scanner sc = new Scanner(System.in);
static String[] books={"java","c","python"};
static final double ForTeacher=0.5;
static final double ForStudent=0.3;
static final double ForAlien=0.1;
public static void main(String[] args) {
System.out.println("---------------------Welcome to our bookstore------------------");
System.out.println("Which book do you want to purchase??\nAns: ");
String yourchoice=sc.nextLine();
if(books[0].toLowerCase().equals(yourchoice.toLowerCase())){
System.out.println("----You are opted for " +books[0]+ " book-----");
WhichPerson(books[0]);
}else if(books[1].toLowerCase().equals(yourchoice.toLowerCase())){
System.out.println("----You are opted for " +books[1]+ " book-----");
WhichPerson(books[1]);
}else if(books[2].toLowerCase().equals(yourchoice.toLowerCase())){
System.out.println("----You are opted for " +books[2]+ " book");
WhichPerson(books[2]);
}else{
System.out.println("------Sorry your expected book is not available here---------");
}
}
static void WhichPerson(String great){
System.out.println("----Are you teacher,student or alien??\nAns: ");
double price=200;
String mychoice=sc.nextLine();
if(mychoice.toLowerCase().equals("teacher")){
price=price-(price*ForTeacher);
totalprice(price);
}else if(mychoice.toLowerCase().equals("student")){
price=price-(price*ForStudent);
totalprice(price);
}else if(mychoice.toLowerCase().equals("alien")){
price=price-(price*ForAlien);
totalprice(price);
}else{
System.out.println("-----Sorry you are not in this group.So get lost from here-----");
}
}
static void totalprice(double pri){
System.out.println("The total price of your selected book is: "+pri);
System.out.println("------Thank you for shopping--------");
}
}
Output:
---------------------Welcome to our bookstore------------------
Which book do you want to purchase??
Ans:
python
----You are opted for python book
----Are you teacher,student or alien??
Ans:
teacher
The total price of your selected book is: 100.0
------Thank you for shopping--------
package firstclass;
import java.util.Scanner;
public class Bookstor {
static Scanner sc = new Scanner(System.in);
static String[] books={"java","c","python"};
static final double ForTeacher=0.5;
static final double ForStudent=0.3;
static final double ForAlien=0.1;
public static void main(String[] args) {
System.out.println("---------------------Welcome to our bookstore------------------");
System.out.println("Which book do you want to purchase??\nAns: ");
String yourchoice=sc.nextLine();
if(books[0].toLowerCase().equals(yourchoice.toLowerCase())){
System.out.println("----You are opted for " +books[0]+ " book-----");
WhichPerson(books[0]);
}else if(books[1].toLowerCase().equals(yourchoice.toLowerCase())){
System.out.println("----You are opted for " +books[1]+ " book-----");
WhichPerson(books[1]);
}else if(books[2].toLowerCase().equals(yourchoice.toLowerCase())){
System.out.println("----You are opted for " +books[2]+ " book");
WhichPerson(books[2]);
}else{
System.out.println("------Sorry your expected book is not available here---------");
}
}
static void WhichPerson(String great){
System.out.println("----Are you teacher,student or alien??\nAns: ");
double price=200;
String mychoice=sc.nextLine();
if(mychoice.toLowerCase().equals("teacher")){
price=price-(price*ForTeacher);
totalprice(price);
}else if(mychoice.toLowerCase().equals("student")){
price=price-(price*ForStudent);
totalprice(price);
}else if(mychoice.toLowerCase().equals("alien")){
price=price-(price*ForAlien);
totalprice(price);
}else{
System.out.println("-----Sorry you are not in this group.So get lost from here-----");
}
}
static void totalprice(double pri){
System.out.println("The total price of your selected book is: "+pri);
System.out.println("------Thank you for shopping--------");
}
}
Output:
---------------------Welcome to our bookstore------------------
Which book do you want to purchase??
Ans:
python
----You are opted for python book
----Are you teacher,student or alien??
Ans:
teacher
The total price of your selected book is: 100.0
------Thank you for shopping--------
Screenshots
Program:1
Program : 2
Output
Wednesday, November 26, 2014
Creating Array List With Scanning In Java
Program:
import java.util.Scanner;
public class practice {
public static void main(String[] args){
int[] public_ara=new int[100];
System.out.println("Enter some numbers: ");
Scanner in=new Scanner(System.in);
for(int j=0;j<5;j++){
public_ara[j]=in.nextInt();
}
System.out.println("Serial\taralist");
for(int i=0;i<5;i++){
System.out.println(i + "\t" +public_ara[i]);
}
}
}
Output:
Enter some numbers:
15
13
54
21
62
Serial aralist
0 15
1 13
2 54
3 21
4 62
import java.util.Scanner;
public class practice {
public static void main(String[] args){
int[] public_ara=new int[100];
System.out.println("Enter some numbers: ");
Scanner in=new Scanner(System.in);
for(int j=0;j<5;j++){
public_ara[j]=in.nextInt();
}
System.out.println("Serial\taralist");
for(int i=0;i<5;i++){
System.out.println(i + "\t" +public_ara[i]);
}
}
}
Output:
Enter some numbers:
15
13
54
21
62
Serial aralist
0 15
1 13
2 54
3 21
4 62
ScreenShot
Program
Output
Tuesday, November 25, 2014
Convert Fahrenheit to Celsius In Java
Program:
import java.util.Scanner;
public class f2c {
public static void main(String[] arrgs){
Scanner in=new Scanner(System.in);
double x,result;
System.out.println("Enter temperature in farenhiet: ");
x=in.nextDouble();
result=((x-32)*5)/9;
System.out.println("The temperature converts into celcius and that is: "+result);
}
}
Output:
Enter temperature in farenhiet:
278.15
The temperature converts into celcius and that is: 136.75
import java.util.Scanner;
public class f2c {
public static void main(String[] arrgs){
Scanner in=new Scanner(System.in);
double x,result;
System.out.println("Enter temperature in farenhiet: ");
x=in.nextDouble();
result=((x-32)*5)/9;
System.out.println("The temperature converts into celcius and that is: "+result);
}
}
Output:
Enter temperature in farenhiet:
278.15
The temperature converts into celcius and that is: 136.75
Screenshots
Program
Print Odd or Even Number In java
Program:
package odd_or_even;
import java.util.Scanner;
public class jor_bijor {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int x;
System.out.println("Enter a number to check: ");
x=in.nextInt();
if(x % 2==0){
System.out.println("The number is even");
}
else{
System.out.println("The number is odd");
}
}
}
Output:
Enter a number to check:
15
The number is odd
package odd_or_even;
import java.util.Scanner;
public class jor_bijor {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int x;
System.out.println("Enter a number to check: ");
x=in.nextInt();
if(x % 2==0){
System.out.println("The number is even");
}
else{
System.out.println("The number is odd");
}
}
}
Output:
Enter a number to check:
15
The number is odd
Monday, November 17, 2014
GUI==>Graphical User Interface In Java
Program:
package java_tutorial_1;
import javax.swing.JOptionPane;
public class gui {
public static void main(String[] args){
String fn=JOptionPane.showInputDialog("Enter first number: ");
String sn=JOptionPane.showInputDialog("Enter second number: ");
int num1=Integer.parseInt(fn);
int num2=Integer.parseInt(sn);
int res=num1+num2;
JOptionPane.showMessageDialog(null,"answer "+ res,"title", JOptionPane.PLAIN_MESSAGE);
}
}
package java_tutorial_1;
import javax.swing.JOptionPane;
public class gui {
public static void main(String[] args){
String fn=JOptionPane.showInputDialog("Enter first number: ");
String sn=JOptionPane.showInputDialog("Enter second number: ");
int num1=Integer.parseInt(fn);
int num2=Integer.parseInt(sn);
int res=num1+num2;
JOptionPane.showMessageDialog(null,"answer "+ res,"title", JOptionPane.PLAIN_MESSAGE);
}
}
Screenshots
Program
Output 1
Output 2
Output 3
Friday, November 14, 2014
Wednesday, November 12, 2014
Add variables using for loop In Java
Program:
package sum_project;
import java.util.Scanner;
public class summation {
public static void main(String[] args){
Scanner moni=new Scanner(System.in);
int userinput;
int sum=0;
System.out.println("Enter a number: ");
userinput=moni.nextInt();
if(userinput<0){
System.out.println("there are no number : ");
}
else{
for(int i=1;i<=userinput;i++){
sum=sum+i;
}
}
System.out.println("The sum is: "+sum);
}
}
Output:
Enter a number:
20
The sum is: 210
package sum_project;
import java.util.Scanner;
public class summation {
public static void main(String[] args){
Scanner moni=new Scanner(System.in);
int userinput;
int sum=0;
System.out.println("Enter a number: ");
userinput=moni.nextInt();
if(userinput<0){
System.out.println("there are no number : ");
}
else{
for(int i=1;i<=userinput;i++){
sum=sum+i;
}
}
System.out.println("The sum is: "+sum);
}
}
Output:
Enter a number:
20
The sum is: 210
Screenshot:
Program:
Output:
Mini Project Word Ripp In Java Language
Program:
package wordgame;
import java.util.Scanner;
public class word {
public static void main(String[] args){
String name;
String city;
String district;
String fathername;
String mothername;
String schoolname;
String thana;
Scanner moni=new Scanner(System.in);
System.out.println("Enter your name: ");
name=moni.nextLine();
System.out.println("Enter your city name: ");
city= moni.nextLine();
System.out.println("Enter your district name: ");
district=moni.nextLine();
System.out.println("Enter father name: ");
fathername=moni.nextLine();
System.out.println("Enter your mother name: ");
mothername=moni.nextLine();
System.out.println("Enter your school name: ");
schoolname=moni.nextLine();
System.out.println("Enter your thana name: ");
thana=moni.nextLine();
System.out.println("My name is "+name+ "."+
" I live in "+city+"."+" My father's name is "+fathername+"."+" My mother's name is "
+mothername+ "."+" My school name was "+schoolname+"."+" My district name is "+district+"."+
" And the thana is "+thana+".");
}
}
Output:
Enter your name:
jack
Enter your city name:
Naraingonj
Enter your district name:
Dhaka
Enter father name:
Redclief
Enter your mother name:
Belly
Enter your school name:
Udaigar school
Enter your thana name:
Dhaka
My name is jack. I live in Naraingonj. My father's name is Redclief. My mother's
name is Belly. My school name was Udaigar school. My district name is Dhaka. An
d the thana is Dhaka.
package wordgame;
import java.util.Scanner;
public class word {
public static void main(String[] args){
String name;
String city;
String district;
String fathername;
String mothername;
String schoolname;
String thana;
Scanner moni=new Scanner(System.in);
System.out.println("Enter your name: ");
name=moni.nextLine();
System.out.println("Enter your city name: ");
city= moni.nextLine();
System.out.println("Enter your district name: ");
district=moni.nextLine();
System.out.println("Enter father name: ");
fathername=moni.nextLine();
System.out.println("Enter your mother name: ");
mothername=moni.nextLine();
System.out.println("Enter your school name: ");
schoolname=moni.nextLine();
System.out.println("Enter your thana name: ");
thana=moni.nextLine();
System.out.println("My name is "+name+ "."+
" I live in "+city+"."+" My father's name is "+fathername+"."+" My mother's name is "
+mothername+ "."+" My school name was "+schoolname+"."+" My district name is "+district+"."+
" And the thana is "+thana+".");
}
}
Output:
Enter your name:
jack
Enter your city name:
Naraingonj
Enter your district name:
Dhaka
Enter father name:
Redclief
Enter your mother name:
Belly
Enter your school name:
Udaigar school
Enter your thana name:
Dhaka
My name is jack. I live in Naraingonj. My father's name is Redclief. My mother's
name is Belly. My school name was Udaigar school. My district name is Dhaka. An
d the thana is Dhaka.
Screenshots:
Program:
Output:
Mini project Miles per gallon In Java Language
Program:
package milespergalon;
import java.util.Scanner;
//class method
public class mpg {
//main method
public static void main(String[] args){
double miles_used;
double galon_used;
double mile_per_galon;
Scanner moni=new Scanner(System.in);
System.out.println("How many miles you have driven: ");
miles_used=moni.nextDouble();
System.out.println("How many galons you have used: ");
galon_used=moni.nextDouble();
mile_per_galon=miles_used/galon_used;
System.out.println("Here this is your main result miles per galon is 25" + mile_per_galon);
}
}
Output:
How many miles you have driven:
30
How many galons you have used:
12
Here this is your main result miles per galon is 2.5
package milespergalon;
import java.util.Scanner;
//class method
public class mpg {
//main method
public static void main(String[] args){
double miles_used;
double galon_used;
double mile_per_galon;
Scanner moni=new Scanner(System.in);
System.out.println("How many miles you have driven: ");
miles_used=moni.nextDouble();
System.out.println("How many galons you have used: ");
galon_used=moni.nextDouble();
mile_per_galon=miles_used/galon_used;
System.out.println("Here this is your main result miles per galon is 25" + mile_per_galon);
}
}
Output:
How many miles you have driven:
30
How many galons you have used:
12
Here this is your main result miles per galon is 2.5
Screenshot
Program
Output By input Value 30&12
Tuesday, November 11, 2014
Multiple Class In Java
Program:
package nulticlass;
public class multi {
public static void main(String[] args){
multa object=new multa();
object.mela();
object.another_mela();
}
}
public class multa {
public void mela(){
System.out.println("here this is multi class in this program");
}
public void another_mela(){
int a=12,b=48,result=a+b;
System.out.println("the output of the method is "+ result);
}
}
Output:
here this is multi class in this program
the output of the method is 60
package nulticlass;
public class multi {
public static void main(String[] args){
multa object=new multa();
object.mela();
object.another_mela();
}
}
public void mela(){
System.out.println("here this is multi class in this program");
}
public void another_mela(){
int a=12,b=48,result=a+b;
System.out.println("the output of the method is "+ result);
}
}
Output:
here this is multi class in this program
the output of the method is 60
Screenshot
Program
Step 1:class
Step 2:Another class
Output
Sunday, November 9, 2014
Indentation In PHP
Indentation:
It means using Curly brackets { } in programming.
<?php
//indentation two types....1.end of line indentation
$text=15;
if($text==15){ // here this is the end of line indentation
echo 'The number is really fifteen';
}else{
echo 'The number is not fifteen';
}
// 2.next line indentation
$text=12;
if($text==15)
{ // here this is the next line indentation
echo 'The number is really fifteen';
}
else
{
echo 'The number is not fifteen';
}
?>
Output:
The number is really fifteen
The number is not fifteen
It means using Curly brackets { } in programming.
<?php
//indentation two types....1.end of line indentation
$text=15;
if($text==15){ // here this is the end of line indentation
echo 'The number is really fifteen';
}else{
echo 'The number is not fifteen';
}
// 2.next line indentation
$text=12;
if($text==15)
{ // here this is the next line indentation
echo 'The number is really fifteen';
}
else
{
echo 'The number is not fifteen';
}
?>
Output:
The number is really fifteen
The number is not fifteen
Screenshots:
Program:
Output
Monday, November 3, 2014
Monday, October 20, 2014
Sunday, October 19, 2014
Subscribe to:
Posts (Atom)