Checking character case class characterCase { public static void main (String arg[]) { char c = ‘A’; if (isUpperCase(c)) { System.out.println(c + “ is.

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

Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 3: Flow Control I: For Loops.
Introduction to Programming
Introduction to Computer Science Robert Sedgewick and Kevin Wayne Copyright © Recursive GCD Demo public class.
Introduction to Computer Science Robert Sedgewick and Kevin Wayne Recursive Factorial Demo pubic class Factorial {
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Software Engineering Implementation Lecture 3 ASPI8-4 Anders P. Ravn, Feb 2004.
Craps. /* * file : Craps.java * file : Craps.java * author: george j. grevera, ph.d. * author: george j. grevera, ph.d. * desc. : program to simulate.
C Characters & Strings Character Review Character Handling Library Initialization String Conversion Functions String Handling Library Standard Input/Output.
1 Working with String Duo Wei CS110A_ Empty Strings An empty string has no characters; its length is 0. Not to be confused with an uninitialized.
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
Chapter 7 Strings F Processing strings using the String class, the StringBuffer class, and the StringTokenizer class. F Use the String class to process.
Java Programming Strings Chapter 7.
By Senem Kumova Metin 1 POINTERS + ARRAYS + STRINGS REVIEW.
Programming Character I/O. COMP102 Prog. Fundamentals I: Character I/O/ Slide 2 More on char Type l Constant Declaration: const char star = '*'; l Variable.
ISQA 360 – July 8, 2002 Methods Dr. Sergio Davalos.
Character I/O. COMP104 Character I/O Slide 2 Data Type: char * Constant declaration const char star = '*'; * Variable declaration char resp; * Variable.
Characters. COMP104 Lecture 21 / Slide 2 Data Type: char * Constant declaration const char star = '*'; * Variable declaration char resp; * Variable assignment.
1 More About Methods in Java CSC 1401: Introduction to Programming with Java Week 7 – Lecture 3 Wanda M. Kunkle.
CS Nov 2006 C-strings.
Parameters, Arguments, Local Variables, and Scope CSC 1401: Introduction to Programming with Java Week 8 – Lecture 1 Wanda M. Kunkle.
1 Methods Instructor: Mainak Chaudhuri
INPUT/OUTPUT STATEMENT ADDITION SLIDES. Console.ReadLine() – Use to get the input (String) from user Convert string to other data type – int.Parse() 
1 Text Processing. 2 Type char char : A primitive type representing single characters. –A String is stored internally as an array of char String s = "Ali.
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
Characters. Character Data char data type – Represents one character – char literals indicated with ' '
1 Announcements B7 tutorial today in CS103 –In CSE department –Ask at entry desk for direction to CS103.
1 CSC 201: Computer Programming I Lecture 2 B. S. Afolabi.
The character data type char. Character type char is used to represent alpha-numerical information (characters) inside the computer uses 2 bytes of memory.
Java Expressions MIS 3023 Business Programming Concepts II The University of Tulsa Professor: Akhilesh Bajaj All slides in this presentation ©Akhilesh.
Coding Bat: Ends in ly Given a string of even length, return a string made of the middle two chars, so the string "string" yields "ri". The string.
1 More data types Character and String –Non-numeric variables –Examples: char orange; String something; –orange and something are variable names –Note.
“Great leaders are never satisfied with current levels of performance. They are restlessly driven by possibilities and potential achievements.” – Donna.
Chapter 3A Strings. Using Predefined Classes & Methods in a Program To use a method you must know: 1.Name of class containing method (Math) 2.Name of.
Methods: functions & procedures. Top-down programming Divide-and-conquer technique Divide-and-conquer technique Problem is broken down into a series of.
Converting string to integer class StringToInt { public static void main (String arg[]) { // Assume arg[0] is the input string int result = 0, pos; int.
1 Advanced Programming Examples Output. Show the exact output produced by the following code segment. char[,] pic = new char[6,6]; for (int i = 0; i
1 Control Structures (Chapter 3) 3 constructs are essential building blocks for programs Sequences  compound statement Decisions  if, switch, conditional.
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);
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.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Output Programs These slides will present a variety of small programs. Each program has a control structure that was introduced in this chapter. Our concern.
Review by Mr. Maasz, Summary of Chapter 2: Starting Out with Java.
(Dreaded) Quiz 2 Next Monday.
Introduction to programming in java
Java for Beginners University Greenwich Computing At School DASCO
Java String Methods - Codehs
using System; namespace Demo01 { class Program
Sum of natural numbers class SumOfNaturalNumbers {
Building Java Programs
Agenda Warmup Finish 2.4 Assignments
Building Java Programs Chapter 4.3
Maximization and Minimization Problems
יסודות מדעי המחשב – תרגול 4
Classes Variables That Are Not of a Built-in Type Are Objects
TO COMPLETE THE FOLLOWING:
Introduction to Java Programming
An Introduction to Java – Part I, language basics
Wrapper Classes The java.lang package contains wrapper classes that correspond to each primitive type: Primitive Type Wrapper Class byte Byte short Short.
Propositional Equivalences Rosen 5th and 6th Editions section 1.2
Recursive GCD Demo public class Euclid {
AKA the birth, life, and death of variables.
Lecture 10 Strings CSE /26/2018.
class PrintOnetoTen { public static void main(String args[]) {
Building Java Programs
C Characters and Strings
More on iterations using
Week 3 - Friday COMP 1600.
Instructor: Mainak Chaudhuri
Presentation transcript:

Checking character case class characterCase { public static void main (String arg[]) { char c = ‘A’; if (isUpperCase(c)) { System.out.println(c + “ is upper case.”); } else if (isLowerCase(c)) { System.out.println(c + “ is lower case.”); } else { System.out.println(c + “ is not in English alphabet.”); } }// continued in next slide

Checking character case public static boolean isUpperCase (char c) { return (isBetween(‘A’, c, ‘Z’)); } public static boolean isLowerCase (char c) { return (isBetween(‘a’, c, ‘z’)); } // continued in next slide

Checking character case public static boolean isBetween (char a, char b, char c) { return ((a <= b) && (b <= c)); } } // end class

Case conversion class convertCase { public static void main (String arg[]) { char c = ‘M’; System.out.println(“Original: ” + c); if (isBetween(‘A’, c, ‘Z’)) { System.out.println(“After conversion: ” + toLower(c)); } else if (isBetween(‘a’, c, ‘z’)) { System.out.println(“After conversion: ” + toUpper(c)); } else { System.out.println(“Cannot convert case!”); } } // continued in the next slide

Case conversion public static boolean isBetween (char a, char b, char c) { return ((a <= b) && (b <= c)); } public static char toLower (char c) { return (c – ‘A’ + ‘a’); } public static char toUpper (char c) { return (c – ‘a’ + ‘A’); } } // end class

Local variable example class local { public static void change1(int n){ n=5; } public static int change2(int n){ n=5; return n; } public static void main (String args[]) { int n = 0; int x = 0; change1(n); System.out.println("n="+n); x = change2(n); System.out.println("n="+n+" and x="+x); }