Object:-
Lets assume there is a class Matrix.
To create its object we will simply write
Matrix m = new Matrix();
OR
Matrix m;
m = new Matrix();
Reading an input:-
Here we will create object of console class to read a number, For this we will have to import java.io.*;
Console con = System.console();
String str;
str = con.readline();
Sample code:-
import java.io.*;
class ReadData
{
public static void main(String args[])
{
Console con = System.console();
String name, city;
System.out.println("Enter your name");
name = con.readLine();
System.out.println("Where do you live?");
city = con.readLine();
System.out.println("Hello "+name+" from "+city+" You are welcome" );
}
}
Lets assume there is a class Matrix.
To create its object we will simply write
Matrix m = new Matrix();
OR
Matrix m;
m = new Matrix();
Reading an input:-
Here we will create object of console class to read a number, For this we will have to import java.io.*;
Console con = System.console();
String str;
str = con.readline();
Sample code:-
import java.io.*;
class ReadData
{
public static void main(String args[])
{
Console con = System.console();
String name, city;
System.out.println("Enter your name");
name = con.readLine();
System.out.println("Where do you live?");
city = con.readLine();
System.out.println("Hello "+name+" from "+city+" You are welcome" );
}
}
No comments:
Post a Comment