Forum : console input reading input
Brief description  about Online courses   join in Online courses
View Harini  J 's Profile

console input reading input

IO/Console Input
1.Take two numbers as input from the console. Your program should add these two numbers and print if their sum is odd or even.

import java.io.*;

class Sum
{
public static void main(String args[])throws IOException
{

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int a[]=new int[2];
int res,i=1,b,c;
System.out.println("Enter two numbers");
while(i<3)
{

a[i]=(char)br.read();
if(i==1)
b=a[i];
else
c=a[i];
i ;
}

res=a[i] a[i];
if((res%2)==0)
System.out.println("It is even");
else
System.out.println("It is odd");

}
}

I am not able to get output for above program.please help me out.
Asked by Harini J | Aug 9, 2010 |  Reply now
Replies (1)
View arun kumar das 's Profile
Hi Harini,

Try below program, it works.

import java.io.*;
class Test1
{
public static void main(String[] args)throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter two numbers");
int i=Integer.parseInt(br.readLine());
int j=Integer.parseInt(br.readLine());
int z=i+j;
System.out.println("Sum of the two numbers is :"+z);
if(z%2==0)
{
System.out.println("Sum is even");
}
else
{
System.out.println("Sum is odd");
}
}
}

Regards,
JT
Aug 11, 2010