Išraiškos, sakiniai ir blokai

Slides:



Advertisements
Similar presentations
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Advertisements

Session 3 Algorithm. Algorithm Algorithm is a set of steps that are performed to solve a problem. The example below describes an algorithm Example Check.
1 More Conditionals Instructor: Mainak Chaudhuri
Introduction to Control Statements Presented by: Parminder Singh BCA 5 th Sem. [ Batch] PCTE, Ludhiana 5/12/ Control Statements.
5/17/ Programming Constructs... There are several types of programming constructs in JAVA. - If-else construct or ternary operator - while - do-while.
James Tam Intermediate Pascal to Java examples Pascal To Java: The Transition Documentation Variables and constants Advanced input and output Decision.
Copyright 2010 by Pearson Education Building Java Programs Chapter 7 Lecture 7-1: Arrays reading: 7.1 self-checks: #1-9 videos: Ch. 7 #4.
Copyright 2008 by Pearson Education Building Java Programs Chapter 7 Lecture 7-1: Arrays reading: 7.1 self-checks: #1-9 videos: Ch. 7 #4.
SELECTION CSC 171 FALL 2004 LECTURE 8. Sequences start end.
Sorting Arrays. Selection Sort  One of the easiest ways to sort the elements of an array is by using the selection sort algorithm.  Assume that the.
Do You Understand Methods and Parameters? In this section you will be shown 25 different programs. Most of these programs have some type of error. A few,
Sadegh Aliakbary Sharif University of Technology Fall 2012.
Introduction to Java. Main() Main method is where the program execution begins. There is only one main Displaying the results: System.out.println (“Hi.
Sadegh Aliakbary Sharif University of Technology Spring 2011.
Problem Solving using the Java Programming Language May 2010 Mok Heng Ngee Day 5: Arrays.
Chapter 4 คำสั่งควบคุม (control statement) If statement Switch statement While loop and do-while loop For loop and for-each loop Break and continue 1.
Peyman Dodangeh Sharif University of Technology Spring 2014.
Introduction to Programming G50PRO University of Nottingham Unit 8 : Methods 2 - Arrays Paul Tennent
1 Array basics. Data Structures Sometimes, we have data that have some natural structure to them  A few examples: Texts are sequences of characters Images.
More loops while and do-while. Recall the for loop in general for (initialization; boolean_expression; update) { }
Array - CIS 1068 Program Design and Abstraction Zhen Jiang CIS Dept. Temple University SERC 347, Main Campus 12/19/20151.
Review TEST 2 Chapters 4,5,7. QUESTION For which type of operands does the == operator always work correctly: (a) int, (b) double, or (c) String?
Building Java Programs Chapter 7 Arrays Copyright (c) Pearson All rights reserved.
FOR LOOP WALK THROUGH public class NestedFor { public static void main(String [] args) { for (int i = 1; i
Statements and Control Flow The programs we have seen so far do exactly the same list of instructions every time What if we want to do different things.
Programming With Java ICS201 University Of Ha’il1 Chapter 11 Recursion.
A Introduction to Computing II Lecture 1: Java Review Fall Session 2000.
Loops and Logic. Making Decisions Conditional operator Switch Statement Variable scope Loops Assertions.
WAP to find out the number is prime or not Import java.util.*; Class Prime { public static void main(string args[]) { int n,I,res; boolean flag=true;
Lesson 7 Iteration Structures. Iteration is the third control structure we will explore. Iteration simply means to do something repeatedly. All iteration.
Object Oriented Programming Lecture 2: BallWorld.
Object-Oriented Programming Ramzi Saifan Program Control Slides adapted from Steven Roehrig.
Building Java Programs Chapter 7 Arrays Copyright (c) Pearson All rights reserved.
Introduction to Programming using Java Day 3 and 4 Java Language Basics Review The “For” loop Subroutines The “String” class.
Topic 21 arrays - part 1 Copyright Pearson Education, 2010 Based on slides by Marty Stepp and Stuart Reges from "Should.
using System; namespace Demo01 { class Program
Sum of natural numbers class SumOfNaturalNumbers {
Instructor: Mainak Chaudhuri
Control Structures.
Dr. Kyung Eun Park Summer 2017
Function Call Trace public class Newton {
Building Java Programs
Building Java Programs
Advanced Programming in Java
مفاهیم اولیه زبان جاوا Java Basic Concepts
CSC 142 Computer Science II
CSC141 Computer Science I Zhen Jiang Dept. of Computer Science
יסודות מדעי המחשב – תרגול 4
Building Java Programs Chapter 7
null, true, and false are also reserved.
Building Java Programs
Java Language Basics.
Building Java Programs
Building Java Programs
Building Java Programs
Code Animation Examples
python.reset() Also moving to a more reasonable room (CSE 403)
References and Objects
class PrintOnetoTen { public static void main(String args[]) {
Lecture Notes – Week 4 Chapter 5 (Loops).
Scope of variables class scopeofvars {
Classification of numbers
Perfect squares class identifySquareButLessClever {
CSS161: Fundamentals of Computing
Building Java Programs
Building Java Programs
File output; Arrays reading: 6.4 – 6.5, 7.1
Building Java Programs
Exception Objects An exception is an abnormal condition that arises in a code sequence at rum time. Exception is a way of signaling serious problem.
Control Statements:.
Presentation transcript:

Išraiškos, sakiniai ir blokai Operatoriai -> išraiškos -> sakiniai -> blokai Apibrėžimas: Išraiška yra sudaryta iš kintamųjų, operatorių, metodų iškvietimo, apskaičiuojančių vieną rezultatą. Išraiškų pavyzdžiai, grįžties tipas: int cadence = 0; // int anArray[0] = 100; //int System.out.println("Element 1 at index 0: " + anArray[0]); // String int result = 1 + 2; // int if (value1 == value2) // boolean System.out.println("value1 == value2"); //String

Apibrėžimas. Sakiniu vadinama išraiškų grupė, kurios gale yra ; Sakinių tipai: Priskyrimo sakiniai Inkrementacijos ++ ir dekrementacijos -- Metodų iškvietimo Objekto sukūrimo Kintamųjų sukūrimo/paskelbimo Ciklų Pavyzdžiai // Priskyrimo aValue = 8933.234; // Inkrementacijos aValue++; // Metodo iškvietimo System.out.println("Sveikas pasauli!"); // Objekto sukūrimo Dviratis manoDviratis = new Dviratis(); // Kintamojo paskelbimas int ugis = 180; //cm

Apibrėžimas. Bloku vadinama grupė sakinių apskliaustų {} operatoriniais skliaustais Bloke apibrėžti (paskelbti) lokalūs kintamieji galioja tik tame bloke. class BlockDemo { public static void main(String[] args) { boolean condition = true; if (condition) { // 1-ojo bloko pradžia int a = 3, b = 5; System.out.println("Salyga yra." + ( a==b) ); } // 1-ojo bloko pabaiga else { // 2-ojo bloko pradžia int a = 4, b = 4; System.out.println("Salyga yra " + ( a==b) ); } // 2-ojo bloko pabaiga }

Ciklo sakiniai: if, if-else, switch, do, do-while, for, break, continue public class IfStatementDemo { public static void main(String[] args) { int a = 10, b = 20; if (a > b) System.out.println("a > b"); if (a < b) System.out.println("b > a"); } public class IfElseStatementDemo { public static void main(String[] args) { int a = 10, b = 20; if (a > b) { System.out.println("a > b"); } else { System.out.println("b > a"); }

public class SwitchCaseStatementDemo { public static void main(String[] args) { int a = 10, b = 20, c = 30; int status = -1; if (a > b && a > c) { status = 1; } else if (b > c) { status = 2; } else { status = 3; } switch (status) { case 1: System.out.println("a is the greatest"); break; case 2: System.out.println("b is the greatest"); case 3: System.out.println("c is the greatest"); default: System.out.println("Cannot be determined");

public class WhileLoopDemo { public static void main(String[] args) { int count = 1; System.out.println("Printing Numbers from 1 to 10"); while (count <= 10) { System.out.println(count++); } public class DoWhileLoopDemo { public static void main(String[] args) { int count = 1; System.out.println("Printing Numbers from 1 to 10"); do { System.out.println(count++); } while (count <= 10); }

public class Fibonacci { public static void main(String args[]) { System.out.println("Printing Limited set of Fibonacci Sequence"); double fib1 = 0; double fib2 = 1; double temp = 0; System.out.println(fib1); System.out.println(fib2); do { temp = fib1 + fib2; System.out.println(temp); fib1 = fib2; //Replace 2nd with first number fib2 = temp; //Replace temp number with 2nd number } while (fib2 < 5000); }

public class ForLoopDemo { public static void main(String[] args) { System.out.println("Printing Numbers from 1 to 10"); for (int count = 1; count <= 10; count++) { System.out.println(count); } public class CompactForLoopDemo { public static void main(String[] args) { System.out.println("Printing Prime Numbers from 1 to 20"); for (int prime : new int[]{2,3,5,7,11,13,17,19} ) { System.out.println(prime); }

public class ContinueExample { public static void main(String[] args) { System.out.println("Odd Numbers"); for (int i = 1; i <= 10; ++i) { if (i % 2 == 0) continue; // Rest of loop body skipped when i is even System.out.println(i + "\t"); } public class BreakExample { public static void main(String[] args) { System.out.println("Numbers 1 - 10"); for (int i = 1;; ++i) { if (i == 11) break; System.out.println(i + "\t"); } continue ir break su žyme

public class ReturnExample { public static int pirmasNeigimasElementas(int[] a) { for ( int i = 0; i < a.length; i++ ) if ( a[i] < 0 ) return a[i]; return 0; } public class VoidReturnExample { public static void spausdinamePaskutiny(int[] a) { if ( a == null || a.length < 1 ) return; System.out.println( a[a.length-1] ); }