Instructor: Mainak Chaudhuri

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

Types, Variables and Operators Computer Engineering Department Java Course Asst. Prof. Dr. Ahmet Sayar Kocaeli University - Fall 2013.
1 More Conditionals Instructor: Mainak Chaudhuri
Hand Crafting your own program By Eric Davis for CS103.
1 Selection Sort and Quick Sort Instructor: Mainak Chaudhuri
CSCI1402: Lecture 1 Week 6 Dr. David A. Elizondo Centre for Computational Intelligence School of Computing Office: Gateway 6.61
TA: Nouf Al-Harbi NoufNaief.net :::
1 Library Methods and Recursion Instructor: Mainak Chaudhuri
Computer Programming Lab(4).
Shorthand operators.
1 Methods Instructor: Mainak Chaudhuri
1 Graphs and Search Trees Instructor: Mainak Chaudhuri
1 Linear and Binary Search Instructor: Mainak Chaudhuri
1 Conditionals Instructor: Mainak Chaudhuri
Logical OperatorstMyn1 Logical Operators Using logical operators, we can combine a series of comparisons into a single expression. if(letter>=‘A’ && letter
1 Operators and Expressions Instructor: Mainak Chaudhuri
1 CSC 110AA Introduction to Computer Science for Majors - Spring 2003 Class 5 Chapter 2 Type Casting, Characters, and Arithmetic Operators.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs.
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
CS177 Week2: Recitation Primitive data types and Strings with code examples.
1 Announcements B7 tutorial today in CS103 –In CSE department –Ask at entry desk for direction to CS103.
COM S 207 Method Instructor: Ying Cai Department of Computer Science Iowa State University
1 Examples of Recursion Instructor: Mainak Chaudhuri
1 More data types Character and String –Non-numeric variables –Examples: char orange; String something; –orange and something are variable names –Note.
Take out a piece of paper and PEN. The quiz starts ONE minute after the tardy bell rings. You will have 45 – 90 seconds per question. Determine the output.
FOR LOOP WALK THROUGH public class NestedFor { public static void main(String [] args) { for (int i = 1; i
Methods: functions & procedures. Top-down programming Divide-and-conquer technique Divide-and-conquer technique Problem is broken down into a series of.
Chapter One Lesson Three DATA TYPES ©
CSCI S-1 Section 4. Deadlines for Homework 2 Problems 1-8 in Parts C and D – Friday, July 3, 17:00 EST Parts E and F – Tuesday, July 7, 17:00 EST.
1 Printing characters : Revisited class printcharacter{ public static void main(String arg[]){ char grade=‘A’; System.out.println(grade);// prints A System.out.println((int)grade);
Floating Point ValuestMyn1 Floating Point Values Internally, floating point numbers have three pairs: a sign (positive or negative), a mantissa (has a.
CS001 Introduction to Programming Day 6 Sujana Jyothi
1 Conditionals Instructor: Mainak Chaudhuri
Output Programs These slides will present a variety of small programs. Each program has a compound condition which uses the Boolean Logic that was introduced.
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;
CMSC 150 ARRAYS CS 150: Fri 10 Feb Motivation  Consider a list of your contact addresses: String Zero = String.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Checking character case class characterCase { public static void main (String arg[]) { char c = ‘A’; if (isUpperCase(c)) { System.out.println(c + “ is.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Methods Android Club 2015.
Algorithms and programming
using System; namespace Demo01 { class Program
Elementary Programming
Sum of natural numbers class SumOfNaturalNumbers {
Chapter 10 Arrays.
Chapter 2 Elementary Programming
Instructor: Mainak Chaudhuri
Introduction to programming in java
Examples of class: Using System.in.read ()
Decision statements. - They can use logic to arrive at desired results
Chapter 10 Arrays.
Chapter 6 Arrays.
Computing Adjusted Quiz Total Score
Unit-2 Objects and Classes
TO COMPLETE THE FOLLOWING:
חלק ה שימוש במציין שלם לערך תווי
مساق: خوارزميات ومبادئ البرمجة الفصل الدراسي الثاني 2016/2015
Propositional Equivalences Rosen 5th and 6th Editions section 1.2
AP Java Warm-up Boolean Array.
References, Objects, and Parameter Passing
Recursive GCD Demo public class Euclid {
References and Objects
class PrintOnetoTen { public static void main(String args[]) {
Java Programming with Multiple Classes
Lecture Notes – Week 2 Lecture-2
Scope of variables class scopeofvars {
Scope scope: The part of a program where a variable exists. From its declaration to the end of the { } braces A variable declared in a for loop exists.
Boolean in C++ CSCE 121.
CIS 110: Introduction to Computer Programming
Week 3 - Friday COMP 1600.
Presentation transcript:

Instructor: Mainak Chaudhuri mainakc@cse.iitk.ac.in More Examples Instructor: Mainak Chaudhuri mainakc@cse.iitk.ac.in

Checking case class upperCaseCharacter{ public static void main(String arg[]){ char c=‘0’; boolean isuppercase, islowercase; isuppercase = ((c >= ‘A’) && (c <= ‘Z’)); islowercase = ((c >= ‘a’) && (c <= ‘z’)); System.out.ptintln(“The character is ” + c + “. Uppercase: ” + isuppercase); }

Digits in AP class digitsInAP{ public static void main(String arg[]){ int x = 121; int d0, d1, d2; boolean isAP; d0 = x % 10; d1 = (x/10) % 10; d2 = x/100; isAP = ((d0+d2) == (2*d1)); System.out.println(“The number is: ” + x + “. Digits in AP? ” + isAP); }

Divisibility by 4 class divisibleByFour{ public static void main(String arg[]){ int x = 121; int lastTwoDigits; boolean isdivBy4; lastTwoDigits = x%100; isdivBy4 = ((lastTwoDigits % 4) == 0); System.out.println(“The number is: ” + x + “. Divisible by 4? ” + isdivBy4); }

Exchanging numbers class swapBad{ public static void main(String arg[]){ int x = 121; int y = 200; System.out.println(“x: ” + x + “, y: ” + y); x = x + y; // Could overflow y = x – y; x = x – y; }

Exchanging numbers class swapGood{ public static void main(String arg[]){ int x = 121; int y = 200; int temp; System.out.println(“x: ” + x + “, y: ” + y); temp = x; x = y; y = temp; }