Rana zuwa Yau: Koyon Yaren Shirye-shiryen Java - Kashi na 2


Matsar da mataki a gaba ga labarin da ya gabata akan Rana-Yau: Sashin Shirye-shiryen Java - I. Anan a cikin wannan rubutun zamu koya maganganun sarrafawa da madaukai a cikin Java, wanda ke da matukar amfani wajen haɓaka aikace-aikace.

Idan bayanin a cikin Java yana aiki iri ɗaya idan na sanarwa a cikin kowane yare na shirye-shiryen duniya gami da rubutun harsashi.

Shirye-shiryen 3: kwatanta.java

class compare{ 
public static void main(String args[]){ 
int a,b; 
a=10; 
b=20; 
if(a < b)  
System.out.println("a(" +a+ ")is less than b(" +b+")");  
a=a*2;  
if(a==b)  
System.out.println("a(" +a+ ")is equal to b(" +b+")");  
a=a*2;  
if(a>b) 
System.out.println("a(" +a+ ")is greater than b(" +b+")"); 
} 
}

Adana shi azaman: kwatanta.java. Kuma Hada shi ka gudanar kamar yadda aka nuna.

# javac compare.java
# java compare
a(10)is less than b(20) 
a(20)is equal to b(20) 
a(40)is greater than b(20)

Lura: A cikin shirin na sama

  1. An bayyana aji wanda shine kwatancen.
  2. An bayyana masu haɗewa guda biyu tare da ƙimar farkon 10 da 20 bi da bi.
  3. Idan bayanin zai bincika yanayin kuma yayi aiki bisa ga bayanin. Maimaitawa idan bayanin shine idan (sharadi) bayani;
  4. System.out.println yana buga komai da duk abin da aka sanya tsakanin maganganu biyu. Duk abin da ke cikin ƙididdigar an buga shi yadda yake, kuma a waje na ƙididdigar ana kula da shi mai canzawa.
  5. + haɗuwa ce, wadda ake amfani da ita don haɗa sassa biyu na sanarwa.

Idan kuna da wata kwarewar shirye-shirye, tabbas zaku san muhimmancin maganganun madauki. Anan kuma ga bayanin madauki yana aiki kwatankwacin na sanarwa a kowane yare.

Shirye-shiryen4: forloop.java

class forloop{ 
public static void main(String args[]){ 
int q1; 
for (q1=0; q1<=10; q1++) 
System.out.println("The value of interger: "+q1); 
} 
}

Ajiye shi azaman: forloop.java. Kuma Hada shi ka gudanar kamar yadda aka nuna.

# javac forloop.java
# java forloop
Output:
The value of interger: 0 
The value of interger: 1 
The value of interger: 2 
The value of interger: 3 
The value of interger: 4 
The value of interger: 5 
The value of interger: 6 
The value of interger: 7 
The value of interger: 8 
The value of interger: 9 
The value of interger: 10

Lura: A cikin shirin na sama duk maganganun da lambobin suna da kusan daidai da shirin da ke sama, banda bayanin.

  1. Abinda ke sama don sanarwa shine madauki, wanda ke ci gaba da aiwatarwa akai-akai har sai yanayin ya cika.
  2. The for madauki, gabaɗaya ya kasu kashi uku na lambobin da aka raba da semicolon, kowane ɗayan yana da ma'ana.
  3. Kashi na farko (q1 u003d 0, a cikin shirin da ke sama) shi ake kira initialiser. watau, lambar da ke sama, q1 an tilasta shi farawa da '0'.
  4. Kashi na biyu (q1
  5. Kashi na uku da na karshe (q1 ++, a cikin lambar da ke sama, wanda za'a rubuta shi a matsayin q + 1) ana kiranta iteration.ie, ana neman adadin adadi na sama ya karu da darajar '+1' kowane lokaci ana aiwatar da madauki, har sai yanayin ya cika.

Da kyau shirin da ke sama yana da bayanin haɗin guda ɗaya kawai da 'don madauki'. Amma a cikin mafi girma da ingantaccen shirin ana iya danganta bayanin madauki zuwa bayani fiye da ɗaya ko kuma a ce toshe lambobin.

Shirye-shiryen 5: loopblock.java

class loopblock{ 
	public static void main(String args[]){ 
		int x, y=20;		 
		for(x=0;x<20;x=x+2) 
		{ 
		System.out.println("x is: "+x); 
		System.out.println("y is: "+y); 
		y=y-2; 
} 
} 
}

Adana shi azaman: loopblock.java. Kuma Hada shi ka gudanar kamar yadda aka nuna.

# javac loopblock.java
# java loopblock
x is: 0 
y is: 20 
x is: 2 
y is: 18 
x is: 4 
y is: 16 
x is: 6 
y is: 14 
x is: 8 
y is: 12 
x is: 10 
y is: 10 
x is: 12 
y is: 8 
x is: 14 
y is: 6 
x is: 16 
y is: 4 
x is: 18 
y is: 2

Lura: Shirin da ke sama kusan yayi daidai da shirin da ya gabata, sai dai yana amfani da toshe lambobin da aka alakanta da don madauki. Don aiwatar da sanarwa/toshe sama da ɗaya, muna buƙatar sanya duk bayanan azaman\"{… .codes/toshe ..}" in ba haka ba lambar ba za ta tattara daidai ba.

Ee za mu iya amfani da 'x- -' ko 'x-1' don rage bayani a cikin madauki a inda ake buƙata.

Bayan samun hango dukkan lambobin da yawa, muna buƙatar sanin theoryan ka'idar da zata taimaka a mataki na gaba na coding's.

Abin da muka gani har yanzu shine: Shirye-shiryen Java tarin Fannoni ne, masu ganowa, tsokaci, rubuce-rubuce, masu aiki, masu raba su da kalmomin shiga.

Java yare ne na tsari, ba kwa buƙatar bin kowace doka ta shigar da bayanai. Kuna iya rubuta dukkan lambobin akan layi ɗaya tare da sarari ɗaya tsakanin kowane alama kuma zai aiwatar daidai. Koyaya zaiyi wahala a fahimta.

A cikin masu gano Java akwai sunan aji, sunan hanya ko suna mai canzawa. Zai iya zama babban layi, ƙaramin ƙarami, jerinsu ko haɗakar waɗannan duka waɗannan tare da haruffa na musamman kamar '$'. Koyaya masu ganowa bazai taɓa farawa da ƙimar adadi ba.

Misalan masu gano asali a cikin Java:

s4, New#class, TECmint_class, etc.

An ƙirƙiri darajar yau da kullun a cikin Java ta amfani da zahiri. misali, ‘115 ′ adadi ne na zahiri. ‘3.14‘ shi ne na zahiri mai iyo, ‘X‘ yana da daidaito kuma\"tecmint shine mafi kyawun rukunin yanar gizo wanda aka keɓe don fasahar burbushin" rubutu ne na zahiri.

tsokaci ba shi da alaƙa da aiwatar da lambobi a cikin Java ko wani yare, duk da haka yin tsokaci a tsakanin lambobin ya sanya su iya fahimta kuma ɗan adam ya fahimta. Kyakkyawan aiki ne don rubuta ra'ayoyi a tsakanin layukan lambar, inda ake buƙata.

A Java duk wani abu tsakanin/** da **/ana nufin don takaddara kuma sharhi ne.

An bayyana wasu masu raba a Java.

  1. Iyaye()
  2. Braces {}
  3. Brackets []
  4. Semicolon;
  5. waƙafi,
  6. Lokaci.

Lura: Kowane mai raba yana da ma'ana kuma yana buƙatar amfani dashi a inda ake buƙata, Ba za ku iya amfani da ɗaya a madadin wani ba. Za mu tattauna su a cikin cikakkun bayanai, a cikin ƙarshen lambobin da kansu.

Akwai ajiyayyun kalmomin da aka ayyana a cikin Java. Waɗannan kalmomin ba za a iya amfani da su azaman suna don canji, aji ko hanya ba kamar yadda waɗannan maɓallin keɓaɓɓiyar ma'anar ta da ma'anar ma'ana.

abstract	continue	for	          new	        switch
assert	        default	        goto	          package	synchronized
boolean	        do	        if	          private	this
break   	double	        implements	  protected	throw
byte	        else	        import	          public	throws
case	        enum	        instanceof	  return	transient
catch	        extends	        int	          short	        try
char	        final	        interface	  static	void
class	        finally	        long	          strictfp	volatile
const	        float	        native	          super	        while

Reservedarin kalmomin shiga da kalmomin an adana amma ba a amfani da su. Jin tsoro tare da duk waɗannan abubuwan. A zahiri ba kwa buƙatar firgita, haka nan ba kwa buƙatar haddace duk waɗannan abubuwan. Duk waɗannan za ku saba da su lokacin da kuka fara rayuwa da Java.

Wannan duk don yanzu daga wurina. Kar ka manta da gaya mana yadda kuka ji labarin ya kasance, a cikin ɓangaren sharhi. Zan zo da kashi na gaba na wannan jerin, ba da daɗewa ba. Har zuwa lokacin da za ku ci gaba da kasancewa tare da Tecmint, ku kasance da kasancewa cikin koshin lafiya.