Lecture No 2: How To Take Input From User in C++ JAVA
Lecture No 2: How To Take Input From User in C++ JAVA
Input In Java
Input in java occurred through Scanner class
Scanner is the built in class of java.
Scanner class is present in java.util package
by creating object o
To use Scanner Class we must create an
object that point to this Scanner class
New keyword is used to allocate the
memory
System.in is input stream used to get input
from user
Continued
Scanner a=new Scanner(System.in);
Int number=a.nextInt();
Here a is the object name nextInt is used to
Char Input
For character input we use following method
Scanner a =new Scanner(System.in);
Char c=a.next().charAt(0);
We get the string by this method and takes it
Input In C++
For taking input from user in c++
We use cout and cin method to display and
number
Cin will take the integer value and store it in
the variable named as a.
Comparison of inputs
In JAVA
In C++
Simple Example
In C++
#include<iostream>
using namespace std;
int main()
{
int a,b;
cin>>a;
cin>>b;
int add;
add=a+b;
In Java
*/
public class JavaApplication15 {
/**
*/
public static void main(String[] args) {
int a,b;
a=c.nextInt();
b=c.nextInt();
int add;
add=a+b;
}
Thanks to netbeans
Thanks alot
Contact me at
muhammadhaseeb562@g
mail.com
Mobile no:0336-5686312