Download Programming for beginners and more Study notes Computer science in PDF only on Docsity!
introduction
introduction > dul ht kind oF dala a Vvalubly can hold ard Ihe momar requited Lo Stove ik. Types 0 bicrmitive, Jala buys DSbory Simple values drcvolly in mmol etlon- Pomitive (kotorenet \ dala a D Seo many rUberences bo obyohs 6 oily oe pointets qb Jing bo ploy td Mins) -—_ Data Types in Java jon ie Primitive Data Types Data Types Pius } boolean dala buys . hepteseats one of “two laqual values foe or oy x Its comoaly used im ctaditions aad contial shatemedt New Section 2 Page 1 x at Is woe ma aly Ustd (n Cdaditigns and contiol Statements. Loops x loops aC) ustd to oxtoule a blk oF woe reyualedliy Unkil a gpootEisd condition 15 mbt Types of Loops | Entry Controlled Exit Controlled | l | | for while do-while for(initialization; condition; updation) { } }while(condition) } } hued 2 0 at_lng — ett 15 std wher 6 know the aymber oF ileratioas Cid kadid — owl many Himos iho ladt bo rt pdat a bask) Example: Program demonstrates a for loop that prints numbers from 0 to 10 in a single line. Increment] Decrement import java.io.*; e PB class Geeks { in litre public static void main(string[] args) Start + sation { Iffalse for (int i = @; i <= 10; i++) { System.out.print(i +" ")3 ; } } END Flowchare of far -Loog New Section 2 Page 2 U . U Example: Program demonstrates a while loop that prints numbers from O to 10 ina single line. import java.io.*; eb BB a Geeks { st > Condition . we ublic static void main(String[] args) ai checking { int i = 0; while (i <= 19) { system. out.print(i +" ")3 iy If false t } t Flow vhart oF Uh0 Ig - loop Output @123456789 18 q Jo hile Loop ¥ Tt onsyees tal the cody block executes at last once hoFarg oh ooking tha condi bun Example: Program demonstrates a do-while loop that prints numbers from O to 10 ina single line. ite rue import java.io.*; oro class Geeks { = public static void main(String[] args) start —o|_ Statement |_—_——+ sti int i = @; “ ‘syeten.out.prine(d +" "); [rae } while (i < 16)5 END } Flywoharl of dy-whilé loop Output @123456789 10 Printing out ¥ Guctomeouls orintlal) 1s ob sf he nost vwommoaly New Section 2 Page 4 x stums oul. printlal ) 1s oft OF the nost wommoaly used statemutts bo display ovtput on ty viasole. Example , public class GFG{ . &s a public static void main(String[] args) { system.out.printIn("Hello, World!"); System. out.printIn("Welcome to Java programming.")5 System. out.println("System.out.println prints text on a new line."); } } Output Hello, World! Welcome to Java programming. System.out.println prints text on a new line ¥ skem — Class present in the aver lang parkgg x Ov 15 4 puelic Stabis Ol yout oF type Prnksteuam dobined INSIdG he Sy prem vlast . y ptt lal) Pit, Mothad of tho PriskSh ream class. Tak 1 ¥ WoVuse the Soannct lags Fy rot day Ihe nyt From thy WSOr New Section 2 Page 5 Method nextBoolean(), nextByte(). nextDouble(), nextFloat() nextint(). nextLine(), nextLong() nextShort(), next() Seannee Class Methods Description Used for reading Boolean value. Used for reading Byte value. Used for reading Double value. Used for reading Float value. Used for reading Int value. Used for reading Line value. Used for reading Long value. Used for reading Short value. Used for reading a single word New Section 2 Page 7