Program 1: import java.io.*;
public class Program1
{
public static void main(String ar[])
{
int a,b,c;
DataInputStream ds=new DataInputStream(System.in);
try
{
System.out.printf("Enter the number : ");
a=Integer.parseInt(ds.readLine());
System.out.printf("Enter the number : ");
b=Integer.parseInt(ds.readLine());
c=a+b;
System.out.format("The sum of %d and %d is %d",a,b,c);
}
catch(Exception e)
{
}
}
}
Program 2:
import java.io.*;
public class Program2
{
public static void main(String ar[])throws IOException
{
int a,b,c;
InputStreamReader str=new InputStreamReader(System.in);
BufferedReader bfr=new BufferedReader(str);
System.out.printf("Enter the number : ");
a=Integer.parseInt(bfr.readLine());
System.out.printf("Enter the number : ");
b=Integer.parseInt(bfr.readLine());
c=a+b;
System.out.format("The sum of %d and %d is %d",a,b,c);
}
}
Program 3:
import java.io.*;
public class Program3
{
public static void main(String ar[])throws IOException
{
int a,b,c;
DataInputStream ds=new DataInputStream(System.in);
System.out.printf("Enter te number : ");
a=Integer.parseInt(ds.readLine());
System.out.printf("Enter the number : ");
b=Integer.parseInt(ds.readLine());
c=a+b;
System.out.format("The sum of %d and %d is %d",a,b,c);
}
}
Program 4:
import java.util.*;
public class Program4
{
public static void main(String ar[])
{
Scanner sc=new Scanner(System.in);
int a;
String str=new String();
float f;
System.out.print("Enter the integer value : ");
a=sc.nextInt();
System.out.print("Enter the String value : ");
str=sc.nextLine();
System.out.print("Enter the float value : ");
f=sc.nextFloat();
System.out.printf("The value 0f integer is %d \nThe value of float is %f\n The value of string is %s",a,f,str);
}
}
Program 5:
import javax.swing.*;
public class Program5
{
public static void main(String[] args)
{
String a;
a=JOptionPane.showInputDialog(null, "Enter some text : ");
JOptionPane.showMessageDialog(null,a);
}
}
Wednesday 24 August 2011
at 23:48 | 0 comments | Java
Five Ways to Take Input in Java
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment