//make two class
//You have to run blue colored class i,e FourteenUsingMultipleClasses
class FourteenUsingMultipleClasses {
public static void main(String[] args) {
RefForTutorialThirteen RefForTutorialThirteenObject
=
new RefForTutorialThirteen();
RefForTutorialThirteenObject.simpleMessage("ji");
}
}
public class RefForTutorialThirteen {
public void simpleMessage(String name){
System.out.println("Hey " + name + " Please Join us.");
}
private String girlName;
public void setName(String name){
girlName = name;
}
public String getName(){
return girlName;
}
public void saying(){
System.out.printf("Ohh its Wonder %s",getName());
}
}
Out put is
Hey Hall berry Please Join us.
Sunday, June 2, 2013
Thirteen WhileLoop
class ThirteenWhileLoop {
public static void main(String[] args) {
int counter = 0;
while (counter < 14){
System.out.println("Hey till now I Covered " + counter + " Vedio Tutorial");
counter ++;
System.out.println("its great");
}
}
//out put
Hey till now I Covered 0 Vedio Tutorial
its great
Hey till now I Covered 1 Vedio Tutorial
its great
Hey till now I Covered 2 Vedio Tutorial
its great
Hey till now I Covered 3 Vedio Tutorial
its great
Hey till now I Covered 4 Vedio Tutorial
its great
Hey till now I Covered 5 Vedio Tutorial
its great
Hey till now I Covered 6 Vedio Tutorial
its great
Hey till now I Covered 7 Vedio Tutorial
its great
Hey till now I Covered 8 Vedio Tutorial
its great
Hey till now I Covered 9 Vedio Tutorial
its great
Hey till now I Covered 10 Vedio Tutorial
its great
Hey till now I Covered 11 Vedio Tutorial
its great
Hey till now I Covered 12 Vedio Tutorial
its great
Hey till now I Covered 13 Vedio Tutorial
its great
public static void main(String[] args) {
int counter = 0;
while (counter < 14){
System.out.println("Hey till now I Covered " + counter + " Vedio Tutorial");
counter ++;
System.out.println("its great");
}
}
//out put
Hey till now I Covered 0 Vedio Tutorial
its great
Hey till now I Covered 1 Vedio Tutorial
its great
Hey till now I Covered 2 Vedio Tutorial
its great
Hey till now I Covered 3 Vedio Tutorial
its great
Hey till now I Covered 4 Vedio Tutorial
its great
Hey till now I Covered 5 Vedio Tutorial
its great
Hey till now I Covered 6 Vedio Tutorial
its great
Hey till now I Covered 7 Vedio Tutorial
its great
Hey till now I Covered 8 Vedio Tutorial
its great
Hey till now I Covered 9 Vedio Tutorial
its great
Hey till now I Covered 10 Vedio Tutorial
its great
Hey till now I Covered 11 Vedio Tutorial
its great
Hey till now I Covered 12 Vedio Tutorial
its great
Hey till now I Covered 13 Vedio Tutorial
its great
Twelve Switch Statement
import java.util.Scanner;
class TwelveSwitchStatement {
/**
* @param args
*/
public static void main(String[] args) {
System.out.println("Hi which day's Menu you want");
Scanner santosh = new Scanner(System.in);
String day;
day = santosh.next();
switch(day){
case "Monday":
System.out.println("I can prefer Alu Gobhi ");
break;
case "Tuesday":
System.out.println("I can prefer Alu Mutter ");
break;
case "Wednesday":
System.out.println("I can prefer Baigan ");
break;
case "Thursday":
System.out.println("I can prefer Patta Gobhi ");
break;
case "Friday":
System.out.println("I can prefer Gajar ka Halwa ");
break;
case "Saturday":
System.out.println("I can prefer My wife's kiss ");
break;
case "Sunday":
System.out.println("ohh weekend Its time to Candle light dinner ");
break;
default:
System.out.println("Pl write days like");
System.out.println("Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday");
}
}
}
// Opt put
Hi which day's Menu you want
Monday
I can prefer Alu Gobhi
class TwelveSwitchStatement {
/**
* @param args
*/
public static void main(String[] args) {
System.out.println("Hi which day's Menu you want");
Scanner santosh = new Scanner(System.in);
String day;
day = santosh.next();
switch(day){
case "Monday":
System.out.println("I can prefer Alu Gobhi ");
break;
case "Tuesday":
System.out.println("I can prefer Alu Mutter ");
break;
case "Wednesday":
System.out.println("I can prefer Baigan ");
break;
case "Thursday":
System.out.println("I can prefer Patta Gobhi ");
break;
case "Friday":
System.out.println("I can prefer Gajar ka Halwa ");
break;
case "Saturday":
System.out.println("I can prefer My wife's kiss ");
break;
case "Sunday":
System.out.println("ohh weekend Its time to Candle light dinner ");
break;
default:
System.out.println("Pl write days like");
System.out.println("Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday");
}
}
}
// Opt put
Hi which day's Menu you want
Monday
I can prefer Alu Gobhi
Eleven Logical Operation
import java.util.Scanner;
class ElevenLogicalVariable {
public static void main(String[] args) {
Scanner santosh = new Scanner(System.in);
int girl;
int boy;
System.out.println("Please Put Age of Girl");
girl = santosh.nextInt();
System.out.println("Please Put Age of Boy");
boy = santosh.nextInt();
if (girl >= 18 && boy >= 21)
{
System.out.println("You Can Marry");
}
else
{
System.out.println("You can't Marry Please Wait for The Right time");
}
}
}
// out put
Please Put Age of Girl
18
Please Put Age of Boy
21
You Can Marry
Ten If Statement
import java.util.Scanner;
class TenIfStatement {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Please type 9 ");
Scanner Santosh = new Scanner(System.in);
int test;
test = Santosh.nextInt();
if (test == 9){
System.out.print("Oh good your You typed correctly ");
}
else{
System.out.print("Contition is flase boss its not = 9 ");
}
}
}
==================Out put ==========================
Please type 9
9
Oh good your You typed correctly
Please type 9
10
Contition is flase boss its not = 9
class TenIfStatement {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Please type 9 ");
Scanner Santosh = new Scanner(System.in);
int test;
test = Santosh.nextInt();
if (test == 9){
System.out.print("Oh good your You typed correctly ");
}
else{
System.out.print("Contition is flase boss its not = 9 ");
}
}
}
==================Out put ==========================
Please type 9
9
Oh good your You typed correctly
Please type 9
10
Contition is flase boss its not = 9
Nine Increment and Decrement Operator
import java.util.Scanner;
class NineIncrementdOperator {
public static void main(String[] args) {
Scanner bucky = new Scanner(System.in);
int Increment =5;
int Decrement =5;
Increment ++;
System.out.println( Increment);// here value of Increment is 5+1 = 6
++Increment;
System.out.println(Increment); // here value of Increment is 7
Decrement --;
System.out.println(Decrement);// here value of Increment is 4
--Decrement;
System.out.println(Decrement); // here value of Increment is 3
Increment += 8; // adding 8 to variable
System.out.println(Increment); // here value of Increment is
Increment *= 8; // Multiply 8 to variable
System.out.println(Increment); // here value of Increment is 120
Increment /= 8; // divide 8 to variable
System.out.println(Increment); // here value of Increment is 120 / 8 = 15
Increment %= 8; // remainder 8 to variable
System.out.println(Increment); // here value of Increment is 15 % 8 = 7
}
}
===============Out put ===========================
6
7
4
3
15
120
15
7
class NineIncrementdOperator {
public static void main(String[] args) {
Scanner bucky = new Scanner(System.in);
int Increment =5;
int Decrement =5;
Increment ++;
System.out.println( Increment);// here value of Increment is 5+1 = 6
++Increment;
System.out.println(Increment); // here value of Increment is 7
Decrement --;
System.out.println(Decrement);// here value of Increment is 4
--Decrement;
System.out.println(Decrement); // here value of Increment is 3
Increment += 8; // adding 8 to variable
System.out.println(Increment); // here value of Increment is
Increment *= 8; // Multiply 8 to variable
System.out.println(Increment); // here value of Increment is 120
Increment /= 8; // divide 8 to variable
System.out.println(Increment); // here value of Increment is 120 / 8 = 15
Increment %= 8; // remainder 8 to variable
System.out.println(Increment); // here value of Increment is 15 % 8 = 7
}
}
===============Out put ===========================
6
7
4
3
15
120
15
7
Eight Math Opetaror
import java.util.Scanner;
//here we will make a pair of girl and boy
class EightMathOprator {
public static void main (String args[]){
Scanner bucky = new Scanner(System.in);
int girl , boys, people , left;
String who;
System.out.println("How many Girls :-");
girl = bucky.nextInt();
System.out.println("How many Boys :-");
boys = bucky.nextInt();
if(girl > boys)
{
people = girl / boys;
left = girl - boys;
who = "Girl";
people = girl;
}
else
{
people = boys / girl;
left = boys - girl;
who = "Boys";
people = boys;
}
if (left == 0 ){
System.out.println("We can make pair :- " + people );
}
else
{
System.out.println("We can't make pair As " + left + " " + who + " is more in number ");
}
}
}
================== Out put ====================================
How many Girls :-
56
How many Boys :-
45
We can't make pair As 11 Girl is more in number
//here we will make a pair of girl and boy
class EightMathOprator {
public static void main (String args[]){
Scanner bucky = new Scanner(System.in);
int girl , boys, people , left;
String who;
System.out.println("How many Girls :-");
girl = bucky.nextInt();
System.out.println("How many Boys :-");
boys = bucky.nextInt();
if(girl > boys)
{
people = girl / boys;
left = girl - boys;
who = "Girl";
people = girl;
}
else
{
people = boys / girl;
left = boys - girl;
who = "Boys";
people = boys;
}
if (left == 0 ){
System.out.println("We can make pair :- " + people );
}
else
{
System.out.println("We can't make pair As " + left + " " + who + " is more in number ");
}
}
}
================== Out put ====================================
How many Girls :-
56
How many Boys :-
45
We can't make pair As 11 Girl is more in number
Seven Java Calculator
import java.util.Scanner;
class SevenBasicCalculator {
public static void main ( String args[]){
Scanner bucky = new Scanner ( System.in);
Scanner bucky1 = new Scanner ( System.in);
double fnum, snum, answer ;
String operation;
System.out.println("Enter First Number");
fnum = bucky.nextDouble();
System.out.println("For Addition put + ");
System.out.println("For Substraction put - ");
System.out.println("For Multiplication put * ");
System.out.println("For Division put / ");
System.out.println("For Remainder put %");
operation = bucky1.nextLine() ;
System.out.println("Enter Second Number");
snum = bucky.nextDouble();
if ( operation.equals("+" )){
answer = fnum + snum;
System.out.println("Answer of Addition fnum and snum is := " + answer);
}
else if
(operation.equals("-" )){
answer = fnum - snum;
System.out.println("Answer of Substraction fnum and snum is := " + answer);
}
else if(operation.equals("*" )){
answer = fnum * snum;
System.out.println("Answer of Multiplication fnum and snum is := " + answer);
}
else if(operation.equals("/" )){
answer = fnum / snum;
System.out.println("Answer of Divison fnum and snum is := " + answer);
}
else if (operation.equals("%" )){
answer = fnum % snum;
System.out.println("Answer of Remainder fnum and snum is := " + answer);
}
else
{
System.out.println("Please put valid operator Sign i.e +,-,*,/,% "); }
}
}
==============
Out put
Enter First Number
1
Put Opration
For Addition put +
For Substraction put -
For Multiplication put *
For Division put /
For Remainder put %
+
Enter Second Number
9
Answer of Addition fnum and snum is :=10.0
class SevenBasicCalculator {
public static void main ( String args[]){
Scanner bucky = new Scanner ( System.in);
Scanner bucky1 = new Scanner ( System.in);
double fnum, snum, answer ;
String operation;
System.out.println("Enter First Number");
fnum = bucky.nextDouble();
System.out.println("For Addition put + ");
System.out.println("For Substraction put - ");
System.out.println("For Multiplication put * ");
System.out.println("For Division put / ");
System.out.println("For Remainder put %");
operation = bucky1.nextLine() ;
System.out.println("Enter Second Number");
snum = bucky.nextDouble();
if ( operation.equals("+" )){
answer = fnum + snum;
System.out.println("Answer of Addition fnum and snum is := " + answer);
}
else if
(operation.equals("-" )){
answer = fnum - snum;
System.out.println("Answer of Substraction fnum and snum is := " + answer);
}
else if(operation.equals("*" )){
answer = fnum * snum;
System.out.println("Answer of Multiplication fnum and snum is := " + answer);
}
else if(operation.equals("/" )){
answer = fnum / snum;
System.out.println("Answer of Divison fnum and snum is := " + answer);
}
else if (operation.equals("%" )){
answer = fnum % snum;
System.out.println("Answer of Remainder fnum and snum is := " + answer);
}
else
{
System.out.println("Please put valid operator Sign i.e +,-,*,/,% "); }
}
}
==============
Out put
Enter First Number
1
Put Opration
For Addition put +
For Substraction put -
For Multiplication put *
For Division put /
For Remainder put %
+
Enter Second Number
9
Answer of Addition fnum and snum is :=10.0
Six Getting UserInput
//Getting user Input
import java.util.Scanner;
class SixGettingUserInput
{
public static void main(String args[])
{
Scanner bucky = new Scanner(System.in);
System.out.println("Output :-" /n + bucky.nextLine());
}
}
==============================
// santosh is user input
santosh
Output :- santosh
import java.util.Scanner;
class SixGettingUserInput
{
public static void main(String args[])
{
Scanner bucky = new Scanner(System.in);
System.out.println("Output :-" /n + bucky.nextLine());
}
}
==============================
// santosh is user input
santosh
Output :- santosh
Intermediate Java Tutorial - 2 - Some More String Methods
//Some More String function ( Reference form newbosten)
public class ItTwoSomeMoreStringMethod
{
public static void main(String[] args)
{
String s = "santosh sharma";
//Find the the place s in the "santosh sharma"
System.out.println("place of s in santosh sharma is :-" + s.indexOf("s"));
System.out.println("place of s in santosh sharma from index 5 is :-" + s.indexOf("s",5));
String a = "Bacon";
String b = "monster";
String c = " san tosh ";
//Concat
System.out.println("Result of concatination " + a + b);
// concat from another method
System.out.println("Result of concatination " + a.concat(b));
//replace
System.out.println("Replace B with F in Bacon :- ");
System.out.println(a.replace("B","F"));
//UpperCase
System.out.println("Makes String b Uppercase :-");
System.out.println(b.toUpperCase()) ;
//LowerCase
System.out.println("Makes String b Lower Case :-");
System.out.println(b.toLowerCase());
//trim
System.out.println("Trim the String c");
System.out.println(c.trim());
}
}
++++++++++++++++++++++++++++++++++++++++++++++++++++
Output :-
place of s in santosh sharma is :-0
place of s in santosh sharma from index 5 is :-5
Result of concatination Baconmonster
Result of concatination Baconmonster
Replace B with F in Bacon :-
Facon
Makes String b Uppercase :-
MONSTER
Makes String b Lower Case :-
monster
Trim the String c
san tosh
public class ItTwoSomeMoreStringMethod
{
public static void main(String[] args)
{
String s = "santosh sharma";
//Find the the place s in the "santosh sharma"
System.out.println("place of s in santosh sharma is :-" + s.indexOf("s"));
System.out.println("place of s in santosh sharma from index 5 is :-" + s.indexOf("s",5));
String a = "Bacon";
String b = "monster";
String c = " san tosh ";
//Concat
System.out.println("Result of concatination " + a + b);
// concat from another method
System.out.println("Result of concatination " + a.concat(b));
//replace
System.out.println("Replace B with F in Bacon :- ");
System.out.println(a.replace("B","F"));
//UpperCase
System.out.println("Makes String b Uppercase :-");
System.out.println(b.toUpperCase()) ;
//LowerCase
System.out.println("Makes String b Lower Case :-");
System.out.println(b.toLowerCase());
//trim
System.out.println("Trim the String c");
System.out.println(c.trim());
}
}
++++++++++++++++++++++++++++++++++++++++++++++++++++
Output :-
place of s in santosh sharma is :-0
place of s in santosh sharma from index 5 is :-5
Result of concatination Baconmonster
Result of concatination Baconmonster
Replace B with F in Bacon :-
Facon
Makes String b Uppercase :-
MONSTER
Makes String b Lower Case :-
monster
Trim the String c
san tosh
Intermediate Java Tutorial - 1 - Common String Methods
//Code - Common String Method // from newBoston
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public class ItCommonStringMethod
{
public static void main(String[] args)
{
String[] words = { "funk", "chunk", "furry","baconator"};
// Strat with
for (String w : words)
{
if (w.startsWith("fu"))
System.out.println(w + "starts with fu");
}
// ends with
for (String w : words)
{
if (w.endsWith("unk"))
System.out.println(w + " ends with unk");
}
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You will Get output like below :-
funkstarts with fu
furrystarts with fu
funk ends with unk
chunk ends with unk
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public class ItCommonStringMethod
{
public static void main(String[] args)
{
String[] words = { "funk", "chunk", "furry","baconator"};
// Strat with
for (String w : words)
{
if (w.startsWith("fu"))
System.out.println(w + "starts with fu");
}
// ends with
for (String w : words)
{
if (w.endsWith("unk"))
System.out.println(w + " ends with unk");
}
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You will Get output like below :-
funkstarts with fu
furrystarts with fu
funk ends with unk
chunk ends with unk
Subscribe to:
Posts (Atom)