OBJECT ORIENTED PROGRAMMING THROUGH JAVA : Unit - 1 : User Input to Programs, Escape Sequences

 

User Input to Programs

Here, we make use of the class Scanner of package java.util to give input to the program. Basically, Java Scanner class is a text scanner that breaks the input into using a delimiter. In Java program, importing the class Scanner from package is the first step and should be declare object for performing above stated action.

 

Example: Addition of two integer values

import java.util.Scanner;

// importing Scanner class

public class Add

{

public static void main(String args[])

{

Scanner sc = new Scanner(System.in);   // Declaring object

int a, b;

System.out.println(“Enter any two integer values: ”);

  a = sc.nextInt();      

 b = sc.nextInt();// Here, sc invokes the method nextInt() which reads the value typed by the user.

         System.out.println(“The Sum of given two integer values is : ”+(a+b));

}

}

  Escape Sequences




These characters are consists of a backslash followed by a letter and have special meaning for the compiler. The character escape sequences are as follows:



In fact, these are the instructions to for manipulations in formatting and character representation. For example, “\u0041” is the representation of letter A.

Comments

Popular posts from this blog

How to Get a Job in Top IT MNCs (TCS, Infosys, Wipro, Google, etc.) – Step-by-Step Guide for B.Tech Final Year Students

Common HR Interview Questions

How to Get an Internship in a MNC