Programación I Estructuras de control Java. IF- Else.

Slides:



Advertisements
Similar presentations
Introduction to C# Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
Advertisements

CS110 Programming Language I Lab 10: Arrays I Computer Science Department Spring 2014.
CSCI S-1 Section 5. Deadlines for Problem Set 3 Part A – Friday, July 10, 17:00 EST Parts B – Tuesday, July 14, 17:00 EST Getting the code examples from.
Introduction to Computer Programming Decisions If/Else Booleans.
The switch statement: an N-way selection statement.
LAB 10.
Computer Programming Lab(4).
MSc IT Programming Methodology (2). MODULE TEAM Dr Aaron Kans Dr Sin Wee Lee.
Programming Methodology (1). import java.util.*; public class FindCost3 { public static void main(String[] args ) { Scanner sc = new Scanner(System.in);
Starting Out with Java: From Control Structures through Objects
Basic Java Programming CSCI 392 Week Two. Stuff that is the same as C++ for loops and while loops for (int i=0; i
Byung-Hyun Ha 프로그래밍 실습 #1 Byung-Hyun Ha
Chapter 4 คำสั่งควบคุม (control statement) If statement Switch statement While loop and do-while loop For loop and for-each loop Break and continue 1.
Chapter 5 Case Study. Chapter 5 The RPS Flowchart.
Making Decisions Chapter 5.  Thus far we have created classes and performed basic mathematical operations  Consider our ComputeArea.java program to.
Boolean expressions, part 2: Logical operators. Previously discussed Recall that there are 2 types of operators that return a boolean result (true or.
Input/Output in Java. Output To output to the command line, we use either System.out.print () or System.out.println() or System.out.printf() Examples.
Lecture 3 Decisions (Conditionals). One of the essential features of computer programs is their ability to make decisions. Like a train that changes tracks.
Introduction to Programming G50PRO University of Nottingham Unit 8 : Methods 2 - Arrays Paul Tennent
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) public static void main(String[]
The if-else statement. The if-else statement in Java The if-else statement is the second conditional statement in Java The if-else statement selects one.
OOP (pre) Basic Programming. Writing to Screen print will display the string to the screen, the following print statement will be appended to the previous.
Chapter 6. else-if & switch Copyright © 2012 Pearson Education, Inc.
CS110 Programming Language I Lab 4: Control Statements I Computer Science Department Spring 2014.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
FOR LOOP WALK THROUGH public class NestedFor { public static void main(String [] args) { for (int i = 1; i
Introduction to array: why use arrays ?. Motivational example Problem: Write a program that reads in and stores away 5 double numbers After reading in.
SELF STUDY. IF STATEMENTS SELECTION STRUCTURE if selection statement if … else selection statement switch selection statement.
Java Methods 11/10/2015. Learning Objectives  Be able to read a program that uses methods.  Be able to write a write a program that uses methods.
 CSC111 Quick Revision. Problem Write a java code that read a string, then show a list of options to the user to select from them, where:  L to print.
A Introduction to Computing II Lecture 1: Java Review Fall Session 2000.
©2016 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved. CSC 110 – INTRO TO COMPUTING - PROGRAMMING Switch Statement.
Computer Programming Lab 9. Exercise 1 Source Code package excercise1; import java.util.Scanner; public class Excercise1 { public static void main(String[]
import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter.
1 Simple Input Interactive Input - The Class Scanner n Command-Line Arguments.
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;
Chapter 7 Control Structures. Java has very flexible three looping mechanisms. You can use one of the following three loops:  while Loop  do...while.
Introduction to programming in java
Intro to Programming STARS College of Communication and Information Florida State University Written by: Hannah Brock Alissa Ovalle Nicolaus Lopez Martin.
Introduction of Java Fikri Fadlillah, S.T.
Chapter 2 Clarifications
Exercise 1- I/O Write a Java program to input a value for mile and convert it to kilogram. 1 mile = 1.6 kg. import java.util.Scanner; public class MileToKg.
CSC1401 Input and Output (and we’ll do a bit more on class creation)
Exercise Java programming
Compiling and Running a Java Program
Maha AlSaif Maryam AlQattan
Switch Statement.
Chapter 5: Control Structures II
TK1114 Computer Programming
SELECTION STATEMENTS (1)
Something about Java Introduction to Problem Solving and Programming 1.
Java Methods Making Subprograms.
Control Statement Examples
null, true, and false are also reserved.
חלק ה שימוש במציין שלם לערך תווי
Introduction to Java Programming
Introduction to Classes and Methods
ניתוח זמן ריצה (על קצה המזלג)
محاضرة 1: مقدمة للمسـاق و مراجعـة للأساسيـات
Java Methods Making Subprograms.
Java so far Week 7.
Recursive GCD Demo public class Euclid {
Self study.
References and Objects
class PrintOnetoTen { public static void main(String args[]) {
Lecture Notes – Week 2 Lecture-2
Module 4 Loops and Repetition 4/7/2019 CSE 1321 Module 4.
Module 3 Selection Structures 4/5/2019 CSE 1321 Module 3.
Perfect squares class identifySquareButLessClever {
Consider the following code:
Presentation transcript:

Programación I Estructuras de control Java

IF- Else

/* Ejemplo Estructura IF - */ if (condición) { // Ejecuta si cumple condición instrucciones } else { // Si no se cumple la condición instrucciones }

/* Ejemplo Estructura IF - */ //sin Bracket si es solo una instrucción if (condición) instruccionA; else instruccionB;

Bloque FOR

int f = 0; for (f = 1;f<100; f++){ System.out.print(f); System.out.print(“-”); }

Ejemplo FOR import java.util.Scanner; public class Escuela { public static void main(String[] ar) { Scanner teclado=new Scanner(System.in); int aprobados,reprobados,f,nota; aprobados=0; reprobados=0; for(f=1;f<=10;f++) { System.out.print("Ingrese la nota:"); nota=teclado.nextInt(); if (nota>=7) { aprobados=aprobados+1; } else { reprobados=reprobados+1; } System.out.print("Cantidad de aprobados:"); System.out.println(aprobados); System.out.print("Cantidad de reprobados:"); System.out.print(reprobados); }

estructura de control switch switch( expresión ) { case constante1: sentencia1;... break;... case constanteN: sentenciaN;... break; default: sentencia;... break }

Estructura de control switch public class MiniCalculadora { public static void main(String args[]){ int a = 1; int b = 1; char op = '/'; System.out.print("El resultado es : "); if ( op == '+' ) { System.out.println( a + b); } else if ( op == '-') { System.out.println( a - b); } else if ( op == '*') { System.out.println( a * b); } else if ( op == '/') { System.out.println( a / b); }

Estructura de control switch public class MiniCalculadora{ public static void main(String args[]){ int a = 1, b = 1; char op = '/'; System.out.print("El resultado es : "); switch ( op ) { case '+': System.out.println( a + b ); break; case '-': System.out.println( a - b ); break; case '*': System.out.println( a * b ); break; case '/': System.out.println( a / b ); break; default: System.out.println("error" ); break; }

Estuctura While/Do While

Estuctura While int i = 0; while (true) { //Condición trivial: siempre cierta i++; System.out.println ("Valor de i: " + i); if (i==9) { break;} }

Estructura Do While int contador = 0 ; do { System.out.println ("Contando... " + (contador+1) ); contador += 1; } while (contador<10);