Now, here are some simple java programs you would need for very basic level programming.
1. SUM OF TWO NUMBERS:-
import java.io.*;
class sum
{
public static void main()throws IOException
{
InputStreamReader isr= new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
System.out.println("enter a no.");
String s = br.readLine();
int a = Integer.parseInt(s);
System.out.println("enter another no.");
String p = br.readLine();
int b = Integer.parseInt(p);
int c = a+b;
System.out.println("the sum is "+c);
}
}
Now, here:-
import.java.io.* calls the Input-Output Package of Java
class sum assigns the name of the class
public static void main() is the main function
InputStreamReader and BufferedReader are parts of the io package of java
System.out.println() is for printing.
1. SUM OF TWO NUMBERS:-
import java.io.*;
class sum
{
public static void main()throws IOException
{
InputStreamReader isr= new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
System.out.println("enter a no.");
String s = br.readLine();
int a = Integer.parseInt(s);
System.out.println("enter another no.");
String p = br.readLine();
int b = Integer.parseInt(p);
int c = a+b;
System.out.println("the sum is "+c);
}
}
Now, here:-
import.java.io.* calls the Input-Output Package of Java
class sum assigns the name of the class
public static void main() is the main function
InputStreamReader and BufferedReader are parts of the io package of java
System.out.println() is for printing.
No comments:
Post a Comment