Follow me on Twitter RSS FEED

ලංකාවේ ගැනුන්ගේ වැඩ,

Posted in
කොට්ටාව හන්දියෙන් අවිස්සාවේල්ල බස් රථයකට නැගුනු තරුණියක් බස් රථයේ සෙනග නිසා සෙමි...න් සෙමින් ඉදිරියට යන්නට විය... බස් රථය වේගයෙවන් ඉදිරියට යමින් පවතී..හෝමාගම මංසංධියේදී සෙනග සුළු ප්‍රමාණයක් බැස ගිය අතර.තවත් සෙනග නගින්නට විය.ඒ අතර හැඩි දැඩි පෙනුමෙන් යුතු උස මහත තරුණයෙක් බසයට අපහසුවෙන් ගොඩ උනි.. සෙනග අතරින් ඉදිරියට පැමිණ ඔහු කලින් කී තරුණිය අසල සිට ගත්තේය..බස් රථය ඉදිරියට ඇදෙන්නට විය..ටික වේලාවකින් ...තරුණිය ගස්සා තරුණයාට රැවුවාය.. නැවතත් සුළු මොහොතකින් තරුණිය රවන්නට විය.. තෙවනි වර තරුණිය කට හඩ අවදි කලාය !! '' තමුසේ මහ වනචරයෙක් !! දැන් තුන්පාරක්ම මගේ කකුල පෑගුවා . තමුසේට අක්කලා නංගිලා නැද්ද..කෙල්ලෙක්ට බස් එකකවත් යන්න නෑ..ඔච්චර අමාරුනම් සල්ලි කීයක් හරි දීල ගෑනියෙක් අරං ගිහිං බුදිය ගනිං'' බස් රථයටම ඇසෙන සේ කෑගැසු තරුණිය නිසා තරුණයා දෙස බස් රථයේ සියලු දෑස් යොමු විය.. තරුණයා කෙතරම් හැඩි දැ‍ඩි උවද ඔහුට ඒ වචන දරා ගත නොහැකි විය.ක්ෂණයෙන් ඔහුගේ දෑස් රූරා කදුලු කැට කඩා වැටෙන්නට විට.. ඔහු තම හඩ අවදි කලේය.. ''ම‍ගෙන් වරදක් උනා නම් මට සමා වෙන්න නංගි.මම යුධ හමුදාවේ..පුදුකුඩුඉරිප්පු අවසාන සටනෙදී මට බොම්බයක් පෑගිලා මගේ කකුල මට නැති උනා..මගේ දකුණු අතත් හරියට වැඩ කරන්නේ නෑ.ජීවත් වෙන්න ඕන නිසා ජීවත් වෙනවා නංගි.එදාම මැරිල ගියා නම් අද ඔයා මට බනින්නේ නෑනේ.මට සමාවෙන්න මගේ බොරු කකුලට හැගීම් දැනීම් නෑනේ නංගි ඒකයි එහෙම උනේ..ආය පාරක් මට සමාවෙන්න'' තරුණයා කදුළු පිරි දෑසින් කියාගන කියාගන ගියේය. එසේ කියා තරුණයා පනාගොඩ යුධ හමුදා කදවුර අසලින් බැස ගියේය.. ඔහුට ආසනයක් නොලැබීම ගැන බස් රථයේ සියලු සෙනග කම්පා වූ අතර තරුණිය ලැජ්ජා වෙන් ඇබරි බිම බලන්නට විය.. අප රණවිරුවන්ට මීට වඩා සැලකිය යුතුය.අපේ පණ බේරුවේ ඔවුන්ය..අප ඔවුනට නිසි තැන දී ගරු කල යුතුය..දෙවියන්ද ඔවුන්ව පුදනු ඇත.

අපේ රනවිරුවන් වෙනුවෙන් මෙය share කරන්න

මේ කතාව අපිට එව්ව Srishan Cool ට ගොඩක්‌ ස්‌තුති..

තමන්ගෙම ලස්සන Java Calculator යක් නිර්මානය


අද මම කියලදෙන්නේ java භාවිතා කරලා තමන්ගෙම Calculator 1කක් නිර්මානය කරන ආකරය.මේ සදහා මම java simple Cording පමනයි කරලා තියෙන්නේ..ඔයාලත් මම පහලින් දාලා තියන java cord එක download කරගෙන notepad එකකට copy කරල MyCal.java ලෙස save කරලා compile කර run කර බලන්න.මේ java cording තේරුම්ගැනිමටත් අමතක කන්න එපා..

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVwq4JUWF7b1uADAOuJZFnTh2PDAvT0Q4cr68nNw53BEw5zpg5DZvlSFPg01cTMF3Tk5YoYzdjBz7BimblWzmv7wabfuKrDx0KLww3yLdXTyY_wWh2Xu2ckxwzoPd9WGexlDSbQiRONEQ/s400/download.png VIEW Cording

Java Scientific Calculator design part



පහත downlodw click කර එහි java cord 1ක notepad එකකට copy කර CreateCal.java නමින් save කර compile කර run කර බලන්න


import java.awt.*;

class Cal extends Frame{

Cal(){

setTitle("Scientific Calculator");

setSize(500,230);

setResizable(false);

setBackground(new Color(194,217,241));

` BorderLayout bl=new BorderLayout();

Panel p1=new Panel();

Panel p2=new Panel();

Panel p3=new Panel();

Panel p4=new Panel();

add(p1,bl.SOUTH);

add(p2,bl.NORTH);

add(p3,bl.WEST);

add(p4,bl.EAST);

TextField tf=new TextField(50);

p2.add(tf);

GridLayout gl1=new GridLayout(5,10,6,6);

p1.setLayout(gl1);

GridLayout gl2=new GridLayout(1,3,8,8);

p3.setLayout(gl2);

GridLayout gl3=new GridLayout(1,5,6,6);

p4.setLayout(gl3);

//CREATE cHECKBOX

Checkbox c1=new Checkbox("Degrees",false);

p3.add(c1);

Checkbox c2=new Checkbox("Radians",false);

p3.add(c2);

Checkbox c3=new Checkbox("Grads",false);

p3.add(c3);

Button b0 = new Button (null);

p1.add(b0);

Button b1 = new Button ("Inv");

p1.add(b1);

Button b2 = new Button ("In");

p1.add(b2);

Button b3 = new Button ("(");

p1.add(b3);

Button b4 = new Button (")");

p1.add(b4);

Button b5 = new Button ("<--");

p1.add(b5);

Button b6 = new Button ("CE");

p1.add(b6);

Button b7 = new Button ("C");

p1.add(b7);

Button b8 = new Button ("+/-");

p1.add(b8);

Button b9 = new Button ("v");

p1.add(b9);

Button b10 = new Button ("Int");

p1.add(b10);

Button b11 = new Button ("sinh");

p1.add(b11);

Button b12 = new Button ("sin");

p1.add(b12);

Button b13 = new Button ("X2");

p1.add(b13);

Button b14 = new Button ("n!");

p1.add(b14);

Button b15 = new Button ("7");

p1.add(b15);

Button b16 = new Button ("8");

p1.add(b16);

Button b17 = new Button ("9");

p1.add(b17);

Button b18 = new Button ("/");

p1.add(b18);

Button b19 = new Button ("%");

p1.add(b19);

Button b20 = new Button ("dms");

p1.add(b20);

Button b21 = new Button ("cosh");

p1.add(b21);

Button b22 = new Button ("cos");

p1.add(b22);

Button b23 = new Button ("xY");

p1.add(b23);

Button b24 = new Button ("y_/X");

p1.add(b24);

Button b25 = new Button ("4");

p1.add(b25);

Button b26 = new Button ("5");

p1.add(b26);

Button b27 = new Button ("6");

p1.add(b27);

Button b28 = new Button ("*");

p1.add(b28);

Button b29 = new Button ("1/x");

p1.add(b29);

Button b30 = new Button ("Pi");

p1.add(b30);

Button b31 = new Button ("tanh");

p1.add(b31);

Button b32 = new Button ("tan");

p1.add(b32);

Button b33 = new Button ("x3");

p1.add(b33);

Button b34 = new Button ("3_/x");

p1.add(b34);

Button b35 = new Button ("1");

p1.add(b35);

Button b36 = new Button ("2");

p1.add(b36);

Button b37 = new Button ("3");

p1.add(b37);

Button b38 = new Button ("-");

p1.add(b38);

Button b39 = new Button ("=");

p1.add(b39);

Button b40 = new Button ("F-E");

p1.add(b40);

Button b41 = new Button ("Exp");

p1.add(b41);

Button b42 = new Button ("Mod");

p1.add(b42);

Button b43 = new Button ("log");

p1.add(b43);

Button b44 = new Button ("10x");

p1.add(b44);

Button b45 = new Button ("");

p1.add(b45);

Button b46 = new Button ("0");

p1.add(b46);

Button b47 = new Button (".");

p1.add(b47);

Button b48 = new Button ("+");

p1.add(b48);

Button b49 = new Button ("");

p1.add(b49);

Button b50 = new Button ("MC");

p4.add(b50);

Button b51 = new Button ("MR");

p4.add(b51);

Button b52 = new Button ("MS");

p4.add(b52);

Button b53 = new Button ("M+");

p4.add(b53);

Button b54 = new Button ("M-");

p4.add(b54);

//bUTTON COLOUR

b0.setBackground(new Color(235,242,252));

b1.setBackground(new Color(235,242,252));

b1.setForeground(Color.red);

b2.setBackground(new Color(235,242,252));

b2.setForeground(Color.RED);

b3.setBackground(new Color(235,242,252));

b3.setForeground(Color.RED);

b4.setBackground(new Color(235,242,252));

b4.setForeground(Color.RED);

b5.setBackground(new Color(235,242,252));

b6.setBackground(new Color(235,242,252));

b7.setBackground(new Color(235,242,252));

b8.setBackground(new Color(235,242,252));

b9.setBackground(new Color(235,242,252));

b10.setBackground(new Color(235,242,252));

b10.setForeground(Color.RED);

b11.setBackground(new Color(235,242,252));

b11.setForeground(Color.RED);

b12.setBackground(new Color(235,242,252));

b12.setForeground(Color.RED);

b13.setBackground(new Color(235,242,252));

b13.setForeground(Color.RED);

b14.setBackground(new Color(235,242,252));

b14.setForeground(Color.RED);

b15.setBackground(new Color(235,242,252));

b16.setBackground(new Color(235,242,252));

b17.setBackground(new Color(235,242,252));

b18.setBackground(new Color(235,242,252));

b19.setBackground(new Color(235,242,252));

b20.setBackground(new Color(235,242,252));

b20.setForeground(Color.RED);

b21.setBackground(new Color(235,242,252));

b21.setForeground(Color.RED);

b22.setBackground(new Color(235,242,252));

b22.setForeground(Color.RED);

b23.setBackground(new Color(235,242,252));

b23.setForeground(Color.RED);

b24.setBackground(new Color(235,242,252));

b24.setForeground(Color.RED);

b25.setBackground(new Color(235,242,252));

b26.setBackground(new Color(235,242,252));

b27.setBackground(new Color(235,242,252));

b28.setBackground(new Color(235,242,252));

b29.setBackground(new Color(235,242,252));

b30.setBackground(new Color(235,242,252));

b30.setForeground(Color.RED);

b31.setBackground(new Color(235,242,252));

b31.setForeground(Color.RED);

b32.setBackground(new Color(235,242,252));

b32.setForeground(Color.RED);

b33.setBackground(new Color(235,242,252));

b33.setForeground(Color.RED);

b34.setBackground(new Color(235,242,252));

b34.setForeground(Color.RED);

b35.setBackground(new Color(235,242,252));

b36.setBackground(new Color(235,242,252));

b37.setBackground(new Color(235,242,252));

b38.setBackground(new Color(235,242,252));

b39.setBackground(new Color(235,242,252));

b40.setBackground(new Color(235,242,252));

b40.setForeground(Color.RED);

b41.setBackground(new Color(235,242,252));

b41.setForeground(Color.RED);

b42.setBackground(new Color(235,242,252));

b42.setForeground(Color.RED);

b43.setBackground(new Color(235,242,252));

b43.setForeground(Color.RED);

b44.setBackground(new Color(235,242,252));

b44.setForeground(Color.RED);

b45.setBackground(new Color(235,242,252));

b46.setBackground(new Color(235,242,252));

b47.setBackground(new Color(235,242,252));

b48.setBackground(new Color(235,242,252));

b49.setBackground(new Color(235,242,252));

b50.setBackground(new Color(235,242,252));

b51.setBackground(new Color(235,242,252));

b52.setBackground(new Color(235,242,252));

b53.setBackground(new Color(235,242,252));

b54.setBackground(new Color(235,242,252));

}

}

class CreateCal{

public static void main(String args[]){

Cal c=new Cal();

c.setVisible(true);

}

}




For loop භාවිතය සදහා උදාහරන



Java program හි දී for loop එක ඉතාමත්ම වැදගත් වේ.සමහර වල java Program වලදී for loop එක අපට හිතනෙවත් නැති ආකාරයට භාවිතා කරනු ලබයි.එමනිසා java java program ලිවිමෙදී for loop ඉතාමත් හොදින් හැසිරවිමට දැනසිටිම වැදගත් වේ.අපි කලින් පාඩමෙදී for loop එකේ සරලව භාවිතා කරනා ආකාරය සඛච්චා කලා මතකද?.අපි අද මේ පාඩමෙදි තවදුරටත් for loop හුරුවිම සදහා පහත උදාහරන වැඩසටහන් හොදින් අධ්‍යනය කරමු..





1.

picture for scroll box: program using for loop


පහත ආකාරයට program එක run වේ.





2.

picture for scroll box: program using for loop


පහත ආකාරයට program එක run වේ.




3.

picture for scroll box: program using for loop

පහත ආකාරයට program එක run වේ.




4.


picture for scroll box: program using for loop

පහත ආකාරයට program එක run වේ.






5.
picture for scroll box: program using for loop


පහත ආකාරයට program එක run වේ.




6.

picture for scroll box: program using for loop



පහත ආකාරයට program එක run වේ.




7.


picture for scroll box: program using for loop



පහත ආකාරයට program එක run වේ.




8.

picture for scroll box: program using for loop

පහත ආකාරයට program එක run වේ.






8.

picture for scroll box: program using for loop


පහත ආකාරයට program එක run වේ.

Java තුල Loop භාවිතා කිරිම(while,for...)




අපි අද Java program තුල Loop භාවිතා කර්න අකාරය ගැන ඉගනගනිමු..Java Program වලදී loop භාවිතා කිරිම ඉතාම වැදගත්වේ.අපිට program එකකදී එකම ක්‍රියාව නැවත නැවත සිදුකිරිම සදහා loop ඉතාමත් වැදගත්වේ.
උදාහරනයක් ලෙස
  • අපිට 1 කේ සිට 100000 ඉලක්කම් කර ගැනිමට අවශයයි සිතන්න. ඒ සදහා loop භාවිතා කල හැක.
  • ඔබට කිසියම් statement එකක් කිපවාරයක් එකදිගට print කරගැනිමට loop භාවිතා කල හැක.
  • අපිට කිසියම් දත්ත සමූහයක් විශ්ලේෂණය කිරීමේදී loop භාවිතා කල හැක.
  • විවිද ඇල්ගොරිතම් නිර්මාණයේදී loop භාවිතා කල හැක.


while Loop

while loop එක පහත ආකාරයට ලියනු ලබයි..



while(condition){
//body of loop
}




මෙහිදී condition එක true ලෙස පවතින තාක් loop එක ක්‍රියාත්මක වීම සිදුවේ .condition එක true නම් while loop එක ඇතුලේ ඇති statement execute ක‍ර අවසානයේ නැවත condition එක පරීක්ෂා ක‍රනවා.එය නැවත true නම් while loop එක ඇතුලේ ඇති statement නැවත execute ක‍ර අවසානයේ නැවත condition එක පරීක්ෂා ක‍රනවා.එය false නම් පමනක් while එක ඇතුලේ ඇති statement එක execute කිරීම සිදුනොක‍ර කෙලින්ම loop එකෙන් පිටතට යාම සිදුක‍රනවා. එය true නම් මේ ආකාරයට දිගින් දිගටම මෙය සිදුවනවා.

මෙය තෙරුම් ගැනිමට පහත උදාහරන බලමු.

අපගේ web අඩවිය address 1ක 19වතාවක් විමට program 1k 1ක් ලියමු.



මෙහිදී a සදහා 1 යන අගය ආරම්භයේදී ආදේශ කර ඇත.condition එක true වේ so statement execute වි අවසනයේ දී හි අගය 1කින් ඉහල දැමිම සිදුවේ.ඉන්පසු නැවත condition එක true වේ.නැවත statement execute වි අවසනයේ දී හි අගය 1කින් ඉහල දැමිම සිදුවේ.මේ ආකාරයට a හි අගය 19 වන තෙක් while loop එක ඇතුල execute වේ.a හි අගය 20 ට සමන වු විට condition එක false වේ.ඉන් පසු තවදුරටත් while loop එක ඇතුල execute නොවේ. ඉහත program එක පහත ආකරයට run වේ.




0 සිට 10000 දක්වා සංඛ්‍යා print විමට program 1ක් ලියමු..



class New{
public static void main(String args[]){
int A=0;

while(A<=10000){ System.out.println(A); A++; } } }


Do-while Loop


Do-while Loop එකේ සහ while එකේ වෙනස වන්නේ while දී
condition එක false උනොත් while loop එකේ body එක තුල ඇති කිසිවක් execute නොවේ.නමුත් do-while Loop එකේ condition එක false උනොත් body එක තුල ඇති දේ එක සැරයක් පමනක් execute වේ.do while loop එක පහත ආකාරයට ලියනු ලබයි..

do{
//body of loop
}
while(condition)




මෙය තෙරුම් ගැනිමට පහත උදාහරන බලමු.



class New{
public static void main(String args[]){
int A=1;

do{ System.out.println("www.javaclss.tk");
A++;
}while(A>=10);
}
}

මෙහිදී A සදහා 1 යන අගය ආරම්භයේදී ආදේශ කර ඇත.Statement 1ක print වේ.ඉන් පසු Aහි අගය 2කක් වේ.while loop එකේ condition එක false වේ.එමනිසා loop එකෙන් ඉවත්ව යාම සිදුවේ. නමුත් statement එක 1 සැරයක් පමනක් print වී පවතී.program එක පහත ආකරයට run වේ.
ඉහත program එකේ condition එක true උනොත් loop එක දිගටම ක්‍රියත්මක විම සිදුවේ.එවිට program එක පහත ආකරයට run වේ.
for Loop



for loop එක සහ do-while loop එක යන දෙකම එක සමානවේ.for loop එකේ ඇති වාසිය වනුයේ do-while loop එක ට වඩා පහසුවෙන් ලිවිය හැකි විමයි.for loop එක විශාල java program වලදී බහුලව භාවිතා කරයි.for loop එක අපි හිතන්නැති ආකාටයට use කරන්න පුලුවන්.for loop එක පහත ආකාරයට ලියනු ලබයි..


for(initialization;condition;iteration){
//body
}








මෙය තෙරුම් ගැනිමට පහත උදාහරන බලමු.




class New{
public static void main(String args[]){

for(int A=1;A<=10;A++){ System.out.println(A+"www.javaclss.tk"); } } }


එවිට program එක පහත ආකරයට run වේ.



පහත program එක මගින් for loop එක දෙවරක් යොදා ඇති ආකාරය බලන්න.







පහත උදාහරන බලමු.


public class ForLoop1{
public static void main(String[] args){
for(int i = 1;i <= 9;i++){ for(int j = 1;j <= i;j++){ System.out.print(i); } System.out.println(); } } }


program එක පහත ආකරයට run වේ.

Java Premitive data types (boolean,char,byte,short,int,long,float, double)





අපි අද පාඩමෙන් බලමු java හි Data types ගැන.... Java Premitive data type හි data type 8 ක් අපි ඉගන ගන්නවා...





Java Primitive Data Types (8)

Type
Contains
Default
Size
Range

boolean

true or false false 1 bit NA

char

Unicode character
unsigned
\u0000 16 bits or
2 bytes
0 to 216-1 or
\u0000 to \uFFFF

byte

Signed integer 0 8 bit or
1 byte
-27 to 27-1 or
-128 to 127

short

Signed integer 0 16 bit or
2 bytes
-215 to 215-1 or
-32768 to 32767

int

Signed integer 0 32 bit or
4 bytes
-231 to 231-1 or
-2147483648 to 2147483647

long

Signed integer 0 64 bit or
8 bytes
-263 to 263-1 or
-9223372036854775808 to
9223372036854775807

float

IEEE 754 floating point
single-precision
0.0f 32 bit or
4 bytes
�1.4E-45 to
�3.4028235E+38

double

IEEE 754 floating point
double-precision
0.0 64 bit or
8 bytes
�439E-324 to
�1.7976931348623157E+308






දැන් අපි බලමු Data type use කරලා java program ලියන ආකාරය....මෙහිදී අපි කිසියම් Data Type 1ක කට අදාල variable program 1ක තුල use කරන්නේනම්, ඒවා කුමනData Type 1කට අදාලද යන්න හැදින්විය යුතුය.

උදා -byte a;
byte x=3;
double A=5.5;
boolean b=true;

දැන් අපි Data Type භවිතා කර program ලියමු. එහිදී මෙය වැඩිදුරටත් තේරුම් ගැනිමට හැකිවෙනු ඇත......


class MyProgram{
public static void main(String args[]){

int x=70;
double y=45.98;

System.out.println("x value is = "+x);
System.out.println("x value is = "+y);

}
}


මෙම program 1කේ x සදහා int Data Type 1 කට අදාල අගයකුත්, y සදහා double Data Type 1 කට අදාල අගයකුත්හදුන්වා දී ඇත. තවද System.out.println (sop) ක තුල x සහ y වල අගයන් print කර ඇත.
("x value is = "+x);මෙහි ලකුනක් යොදා ඇත්තේ සංඛ්‍යාත්මඛ එකතුවක් සදහා නොව. ඒ 2ක 1කට ලිවිම සදහාය....


මෙය පහත පරිදි run වේ............


class MyProgram{
.............public static void main(String args[]){

.............char x='Kamal';
..............boolean y=true;


...............System.out.println("His name is = "+x);
................System.out.println("He is a boy = "+y);

.............}
}

char Data Type ඇතුලත් කිරිමේදී එය ' ' ඇතුලට දමා ඇතුලත් කල යුතුය....
මෙය පහත පරිදි run වේ............

java program using char data type



අපි තව program 1 ක් ලියමු.

java program using long,int data type

මෙහිදී අපි * Operator 1ක භාවිතා කරල තියනවා. ඔයල Operators ගැන බය වෙන්න ඒපා..අපි Next පාඩමෙන් Operators use කිරිම ගැන කියලා දෙනවා...
මෙය පහත පරිදි run වේ............


java program using long,int data type

How to use Operators in Java

අද පාඩමෙන් අපි බලමු Java හි Operators මොනවද කියලා සහ ඒවා use කරන ආකාරය..
අපි Java Operators use කරන්නෙ primitive data types වලට පමනි..අපිට Operators ප්‍රදාන වශයෙන් කොටස් 8 කට බෙදා වෙන්කල හැක..ඒවා arithmetic,bitwise, relational,boolean, logical,
assignment, ternary,operator precedence, using parentheses යන ආදි වශයෙනි..

Arithmetic Operator

Arithmetic Operator භාවිතා කරනුයේ සංඛ්‍යාත්මක අගයන් සමග සිදුකරන ගනිත කර්ම සදහාය.
+,-,*,/,% සංඛ්‍යාත්මක අගයන් සදහා භාවිතා කරයි..

+ = එකතුව
- = අඩුකිරිම
* = ගුනකිර්ම
/ = බෙදිම
% =බෙදිම මගින් ලැබෙන ඉතිරිය ගැනිමට

අපි මෙය තේරුම් ගැනිමට උදාහරන program කිපයක් ලියමු.....

class MyProgram2 {
public static void main(String args[]){
int x=75;
int y=80;
int z=90;
int total=x+y+z;
System.out.println("Total is = "+total);
}
}




මෙය Run කල පසු පහත ලෙස print වේ................






අපි දැන් subject 3ක marks වල average ඒක ගැනිමට program 1කක් ලියමු..


class MyProgram2 {
public static void main(String args[]){
double x=75;

double y=80;

double z=90;
double avg=(x+y+z)/3;
System.out.println("Subjet 1 mark is= "+x);
System.out.println("Subjet 2 mark is= "+y);
System.out.println("Subjet 3 mark is= "+z);
System.out.println("Total is = "+avg);
}
}


මෙය Run කල පසු පහත ලෙස print වේ................



කිසියම් value 1කක අගය 1කින් ඉහල දැමිමට X++ හෝ ++X යොදාගනු ලබයි..
තවද කිසියම් value 1කක අගය 1කින් පහල දැමිමට X-- හෝ --X යොදාගනු ලබයි..

මෙය තෙරුම් ගැනිමට පහත උදාහරනය මගින් බලමු.

class New{
public static void main(String args[]){
int A=10;
int B=20;

System.out.println("value of A is ="+A );
System.out.println("value of B is ="+B );

++A;//value 1කක අගය 1කින් ඉහල දැමිම
--B;//value 1කක අගය 1කින් පහල දැමිම

System.out.println("value of ++A is ="+A );
System.out.println("value of --B is ="+B);

}
}

මෙය Run කල පසු පහත ලෙස print වේ................

සිදු කරනා ගනිතකර්මය sop (System.out.println) 1ක තුලදී සිදුකල හැක. පහත උදාහරනය මගින් බලමු..

class New{
public static void main(String args[]){
int A=10;
int B=20;

System.out.println("value of A is ="+A );
System.out.println("value of B is ="+B );
System.out.println("value of ++A is ="+(++A));
System.out.println("value of --B is ="+(--B));
}
}

මෙම පහත උදාහරනය බලන්න...
class New{
public static void main(String args[]){
int A=10;
int B=20;

System.out.println("value of B is ="+B );

System.out.println("value of B++ is ="+B++);

System.out.println("value of B is ="+B );

}
}


මෙහිදී B සදහා අගයක් ආදේශ වනුයේ 2 වන SOP 1ක තුලදී වන අතර නමුත් ඒය 2වන Sop 1ක
තුලදී Print නොවේ ඒ යට හේතුව program 1ක් run වනුයේ වමේ සිට දකුනටය.B++ හිදී
B අගය 1කින් ඉහල දැමිමට සිදුවනුයේ;ලකුනෙන් පසුව වේ.ඒ නිසා next line 1කේ දී ඉහල දැමිමට
සිදුවු B print වේ.



class MyProgram{
public static void main(String args[]){
int a=50;
int b=20;
System.out.println("Value of a = " + a );
System.out.println("Value of b = " + b );
System.out.println("a + b = " + String.valueOf(a+b) );
System.out.println("a - b = " + String.valueOf(a-b) );
System.out.println("a * b = " + String.valueOf(a*b) );
System.out.println("a / b = " + String.valueOf(a/b) );
System.out.println("a % b = " + String.valueOf(a%b) );
System.out.println("a ++ = " + String.valueOf(a++) );
System.out.println("Value of a = " + a );
System.out.println("b -- = " + String.valueOf(b--) );
System.out.println("Value of b = " + b );
}
}



















Bitwise logical Operator









Java Control Statement( IF, If-else....................

අපි අද ඉගනගමු if statement 1ක භාවිත කරන ආකාරය.if statement ඒක සරලව විස්තර කරනවනම් if statement 1ක් භාවිතා කරන්නේ කිසියම් java program 1ක යම්කිසි condition 1ක් සත්‍ය නම් හෝ අසත්‍ය නම් program 1ක ආකර 2කට සිදුකිරිමටය.ඒය සිදුවනුයේ පහත ආකාරයට වේ....

if (condition) {
// Task 1
// Task 2
// Task 3
-----
----- }


පහත උදාහරනය බලමු..

class MyProgram{
public static void main(String args[]){
int a=50;

if(a>=20){
System.out.println("Value of a = " + a );
}
}
}

මෙහිදී a සදහා අගය 50 ක් අදේශ කර ඇත..මෙහිදී a 20 ට වඩ විශාලයි හෝ සමානයි නම් පමනක් statement 1ක print විම සිදුවේ..ඒ සේ නොවුන හොත් කිසිවක් print නොවේ.ඉහත program 1ක පහත පරිදි run වේ..

If -else

if Statement 1කක condition 1ක් සත්‍යනොවුන හොත් යම්කිසි දෙයක් කරගැනිමට if සමග else භවිතා කරයි. ඒය භවිතාවනුයේ පහත ආකාරයට වේ....


if (condition) {
// Task 1
-----}
else {

// Task 2
}

පහත උදාහරනය බලමු...

class MyProgram{
public static void main(String args[]){
int a=15;

if(a>=20){
System.out.println("a is greater than 20 " );
}
else{ System.out.println("a is less than 20 " );

}
}
}
මෙහිදී a සදහා අගය 15 ක් අදේශ කර ඇත. ඒමනිසා (a>=20) condition 1ක අසත්‍ය වේ.ඒමනිසා else තුල ඇති statement 1ක print වේ..ඉහත program 1ක පහත පරිදි run වේ..



පහත උදාහරනය බලමු.මෙහිදි if සහ else කිහිපවතවක් යොදාගෙන subject 3ක Marks වල මධ්‍යන්ය අනුව "A,B,C,S,F" ලෙස Grade කිරිම සදහා program 1ක් ලියමු.


class MyProgram{
public static void main(String args[]){

double mark1=70;
double mark2=58;
double mark3=60;
//calculate average
double avg=(mark1+mark2+mark3)/3;

System.out.println("Average Mark is ="+avg);

//Grade "A,B,C,S,F" using if-else

if(avg>=75){
System.out.println("Your grade is = A ");
}
else if(avg>=65){
System.out.println("Your grade is = B " );
}
else if(avg>=50){
System.out.println("Your grade is = C " );
}
else if(avg>=35){
System.out.println("Your grade is = S" );
}
else{
System.out.println("Your grade is = F " );
}
}
}

ඉහත program 1ක පහත පරිදි run වේ..



පහත උදාහරනයෙන් සංඛ්‍යා 3නකින් විශාලම සංඛ්‍යාව සෙවිම සදහා ලිය ඈති program 1ක බලන්න.එම program 1ක තෙරුම් ගැනිමට එම program 1කට අදාල flow chart (flow chart යනු ගැලිම් සටහන් වන අතර එම flow chart 1කක program 1ක් සිදුවන පිලිවෙල සටහන් කර ඇත.අපි ඉදිරියේදි flow chart ඇසුරෙන් විශාල Java program ප්‍රමනයක් පැහැදිලි කිරිමට බලාපොරොත්තු වෙමි) flow chart 1කද පහතින් දක්වා ඇත.





class MyProgram{
public static void main(String args[]){
int x=10;
int y=4;
int z=4;

if(x>y){
if(z>x){
System.out.println("z is maximum");
}
else{
System.out.println("x is maximum");
}
}
else if(z>y){

System.out.println("z is maximum");
}
else{
System.out.println("y is maximum");
}

}

}
ඉහත program 1ක පහත පරිදි run වේ.....


Related Posts with Thumbnails

ShoutMix chat widget
d