INPUT/OUTPUT STATEMENT ADDITION SLIDES. Console.ReadLine() – Use to get the input (String) from user Convert string to other data type – int.Parse() 

Slides:



Advertisements
Similar presentations
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
Advertisements

1 LECTURE#7: Console Input Overview l Introduction to Wrapper classes. l Introduction to Exceptions (Java run-time errors). l Console input using the BufferedReader.
Primitive Data Types byte, short, int, long float, double char boolean Are all primitive data types. Primitive data types always start with a small letter.
Computer Programming Lab(5).
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 10. Pointers & Dynamic Data Structures.
Reading and Writing to the Console Svetlin Nakov Telerik Corporation
Introduction to Objects A way to create our own types.
Introduction to C# Programming ณภัทร สักทอง Application Program Development.
INPUT/OUTPUT STATEMENT ADDITION SLIDES. Console.ReadLine() – Use to get the input (String) from user Convert string to other data type – int.Parse() 
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
1 Introduction to C# Programming Console applications No visual components Only text output Two types MS-DOS prompt - Used in Windows 95/98/ME Command.
1 Conditional statements Dept. of Computer Engineering Faculty of Engineering, Kasetsart University Bangkok, Thailand.
1 st Semester Module2 Basic C# Concept อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs.
First Programs CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
Reading and Writing to the Console Svetlin Nakov Telerik Corporation
C# Basic Concept Thanachat Thanomkulabut. Naming Rules  Letters, digits and underscores(_)  First character  letter or _  Up to 63 characters long.
1 Introduction to C# Programming Console applications No visual components Only text output Two types MS-DOS prompt - Used in Windows 95/98/ME Command.
1 Interfaces and Abstract Classes Chapter Objectives You will be able to: Write Interface definitions and class definitions that implement them.
Input & Output Statement
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
Chapter 2 Input, Variables and Data Types. JAVA Input JAVA input is not straightforward and is different depending on the JAVA environment that you are.
Additional Pair Programming Exercises 1. Problem 1 For a wheel of radius r feet, how many revolutions are required for that wheel to travel 1 mile? What.
The Math class Java provides certain math functions for us. The Math class contains methods and constants that can be very useful. The Math class is like.
CPU Control Unit Main memory ALU INPUTINPUT OUTPUTOUTPUT ฯ OS Compiler OS   Compiler.
Text Files and String Processing
Method Parameters and Overloading Version 1.0. Topics The run-time stack Pass-by-value Pass-by-reference Method overloading Stub and driver methods.
Console Input / Output Reading and Writing to the Console SoftUni Team Technical Trainers Software University
CSCI 1100/1202 January 23, Class Methods Some methods can be invoked through the class name, instead of through an object of the class These methods.
C# Programming: Basic Concept Part 2 Computer and Programming (204111)
Method OverloadingtMyn1 Method overloading Methods of the same name can be declared in the same class, as long as they have different sets of parameters.
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 2/2/05CS250 Introduction to Computer Science II Pointers.
COP 2551 Introduction to Object Oriented Programming with Java Topics –Introduction to the Java language –Code Commenting –Java Program Structure –Identifiers.
C# Programming Methods.
1 nd Semester Module2 C# Basic Concept Thanawin Rakthanmanon Computer Engineering Department Kasetsart University, Bangkok.
 2002 Prentice Hall. All rights reserved. 1 Chapter 4 – Control Structures Part 1 Outline Counter-Controlled Repetition: Example Sentinel-Controlled Repetition:
1 INPUT/OUTPUT Statements Dept. of Computer Engineering Faculty of Engineering, Kasetsart University Bangkok, Thailand.
Computer Programs CS 1400 Dennis A. Fairclough Version 1.1 CS 1400 Dennis A. Fairclough Version 1.1.
import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter.
Exception Handling SWE 344 Internet Protocols & Client Server Programming.
Lecture 2 Review of 1301 and C# Richard Gesick. Common data types int, long, double, float, char, bool, string.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
1 st Semester Module2 Basic C# Concept อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
© 2006 Lawrenceville Press Slide 1 Chapter 4 Variables  A variable is a name for a value stored in memory.  Variables are created using a declaration.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are created using a declaration statement. For example: Dim.
Variables, Types, Operations on Numbers CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
Object Oriented Programming Lecture 2: BallWorld.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Input/Output Statement Thanachat Thanomkulabut. Input Statement  Console.ReadLine()  Return string  Use to get the input from user  Convert string.
C# Basic Syntax, Visual Studio, Console Input / Output
Software Development I/O and Numbers
C# — Console Application
Lecture Note Set 1 Thursday 12-May-05
Thanachat Thanomkulabut
Chapter 2.
Variables, Loops, Decision Statements, etc
An Introduction to Java – Part I, language basics
ניתוח מערכות מידע תכנות ב C#
The Run-Time Stack and Reference Parameters
C# Programming.
class PrintOnetoTen { public static void main(String args[]) {
Scope of variables class scopeofvars {
CSE Module 1 A Programming Primer
C# Programming: From Problem Analysis to Program Design
Var Name =Console . ReadLine();
Iteration (Loop) part II
Subtype Substitution Principle
Variables and Constants
Presentation transcript:

INPUT/OUTPUT STATEMENT ADDITION SLIDES

Console.ReadLine() – Use to get the input (String) from user Convert string to other data type – int.Parse()  Convert string to integer – double.Parse()  Convert string to double – …. string st = Console.ReadLine(); Run-time error may be occurred if user’s input is incorrect 2

static void Main() { double radius, area; string temp; Console.Write(“Please enter radius value : ”); temp = Console.ReadLine(); radius = double.Parse(temp); area = Math.PI * Math.Pow(radius, 2); Console.WriteLine(“Area of circle = {0:f2}”,area); } We may not have to declare string temp; Instead, combine 2 statements together as following: radius = double.Parse(Console.ReadLine());

public static void Main(string[] args) { int unit; Console.Write("Please input to num : "); unit = int.Parse(Console.ReadLine()); Console.Write(unit); Console.ReadKey(true); } Build finished successfully Run time error occurs if input is a character or string.

Read an ASCII Code of a character. ASCII Code of a character is integer. Console.Read()

 Console.Read returns an ACSII value (Integer) of the code of the first typed character. int i; Console.Write(“Input char:”); i = Console.Read(); Console.WriteLine(i); Input char: A 65 6

7 public static void Main(string[] args) { int val1 = 6;float val2 = 4.2f; double val3 = ;string val4 = "10.5"; char val5 = '7'; Console.WriteLine("1 : {0}",val1+val2); int con1 = (int)(val1+val2); Console.WriteLine("2 : {0}",con1); Console.WriteLine("3 : {0}",val2+val3); double con2 = val2+val3; Console.WriteLine("4 : {0}",con2); Console.WriteLine("5 : {0}",val3+val4); double con3 = val3 + double.Parse(val4); Console.WriteLine("6 : {0}",con3); Console.WriteLine("7 : {0}",val4+val5); int con4 = (int)double.Parse(val4) + (int)val5; Console.WriteLine("8 : {0}",con4);

8 Console.WriteLine("9 : {0}",val1+val5); int con5 = val1 + (int)val5 - '0'; Console.WriteLine("10 : {0}",con5); Console.ReadKey(true); } int val1 = 6; float val2 = 4.2f; double val3 = ; string val4 = "10.5"; char val5 = '7';

public static void Main(string[] args) { int i0 = Console.Read(); char ch0 = (char)(Console.Read()); Console.WriteLine("i0 = {0}, ch0 = {1}",i0,ch0); int i1 = 65; char ch1 = (char)65; Console.WriteLine("i1 = {0}, ch1 = {1}",i1,ch1); int i2 = 'A'; char ch2 = 'A'; Console.WriteLine("i2 = {0}, ch2 = {1}",i2, ch2); Console.ReadKey(true); }

Examples of Read and ReadLine Statements

static void Main() { int num; Console.Write(“Please input to num : ”); num = char.Parse(Console.Read()); Console.Write(num); } Example 1 Compiler errors occurred.

static void Main() { int num; Console.Write("Please input to num : "); num = char.Parse(Console.ReadLine()); Console.Write(num); } inputOutput S83 SciencesRun time error 220Run time error Build finished successfully

static void Main() { char alpha; Console.Write(“Please enter a character : ”); alpha = Convert.ToChar (Console.Read()); Console.Write(alpha); } inputOutput SS SciencesS Build finished successfully

static void Main() { char alpha; Console.Write(“Please enter a character : ”); alpha = Convert.ToChar (Console.ReadLine()); Console.Write(alpha); } inputOutput 55 25Run Time error SS SciencesRun Time error Build finished successfully

static void Main() { char alpha; Console.Write(“Please enter a character : ”); alpha = Convert.ToString(Console.Read()); Console.Write(alpha); } Compiler errors occurred. Cannot implicitly convert type ‘string’ to ‘char’

static void Main() { string alpha; Console.Write(“Please any name : ”); alpha = Convert.ToString(Console.Read()); Console.Write(alpha); } inputOutput S83 SciencesS Build finished successfully

static void Main() { string alpha; Console.Write(“Please any name : ”); alpha = Console.ReadLine(); Console.Write(alpha); } Build finished successfully inputOutput SS Sciences