How to take input and output on console
The following code shows you how a user can take input and output on console in both languages (C#.net and Java)
Code
Input from Console:
In C#.net:
// for taking integer input from user
int i = Console.Read();
// for taking string input from user
string str = Console.ReadLine();
In Java:
Way One
try {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
System.out.println("Input Is : " + br.read());// for taking integer input
} catch (Exception e) {}
Way Second:
try {
FileReader fr = new FileReader(FileDescriptor.in);
BufferedReader br = new BufferedReader(fr);
System.out.println("You Input This : " + br.readLine());// for taking string input
} catch (Exception e) {}
Output on Console:
In C#.net:
// output
Console.Write("i am pakistani");
Console.WriteLine("i love programming");
In Java:
// output
System.out.print("Pakistan Won");
System.out.println("Pakistan Won");
System.out.println("Pakistan Won");
0 comments:
Post a Comment