SOME BASIC JAVA PROGRAMS:-
1. DIVISION OF TWO NUMBERS
import java.io.*;
class division
{
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();
float a = Float.parseFloat(s);
System.out.println("enter another no.");
String p = br.readLine();
float b = Float.parseFloat(p);
float c = a/b;
float d = a%b;
System.out.println("the quotient is "+c);
System.out.println("the remainder is "+d);
}
}
2. DIVISION AND FINDING INTEGRAL QUOTIENT:-
import java.io.*;
class division2
{
public static void main()throws IOException
{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
System.out.println("enter a no.(N)");
String s = br.readLine();
int n = Integer.parseInt(s);
System.out.println("enter another no.(D)");
String p = br.readLine();
int d = Integer.parseInt(p);
double a = new Double(n).doubleValue()/d;
int b = n/d;
float r = n%d;
System.out.println("the quotient is "+a);
System.out.println("the integral quotient is "+b);
System.out.println("the remainder is "+r);
}
}
3. CHECK IF A STUDENT HAS PASSED IN 3 SUBJECTS:-
(CALCULATING AVERAGE AND CHECKING IF AVERAGE>50%)
import java.io.*;
class result
{
public static void main()throws IOException
{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader (isr);
System.out.println("Enter marks in Maths");
String a = br.readLine();
float p = Float.parseFloat(a);
System.out.println("Enter marks in English");
String b = br.readLine();
float q = Float.parseFloat(b);
System.out.println("Enter marks in Maths");
String c = br.readLine();
float r = Float.parseFloat(c);
float n = (p+q+r)/3;
if (n>=50)
{
System.out.println("you have passed");
}
else
{
System.out.println("you have failed");
}
}
}
4. PRINTING OF EVEN NUMBERS FROM 1 TO 50
import java.io.*;
class even_numbers
{
public static void main()
{
for(int i=2 ; i<=50 ; i=i+2)
{
System.out.print(i+" ");
}
}
}
5. PRINTING OF ODD NUMBERS FROM 1 TO 50
import java.io.*;
class odd_numbers
{
public static void main()
{
InputStreamReader isr = new InputStreamReader(System.in);
for(int i=1 ; i<=50 ; i=i+2)
{
System.out.println(i);
}
}
}
1. DIVISION OF TWO NUMBERS
import java.io.*;
class division
{
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();
float a = Float.parseFloat(s);
System.out.println("enter another no.");
String p = br.readLine();
float b = Float.parseFloat(p);
float c = a/b;
float d = a%b;
System.out.println("the quotient is "+c);
System.out.println("the remainder is "+d);
}
}
2. DIVISION AND FINDING INTEGRAL QUOTIENT:-
import java.io.*;
class division2
{
public static void main()throws IOException
{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
System.out.println("enter a no.(N)");
String s = br.readLine();
int n = Integer.parseInt(s);
System.out.println("enter another no.(D)");
String p = br.readLine();
int d = Integer.parseInt(p);
double a = new Double(n).doubleValue()/d;
int b = n/d;
float r = n%d;
System.out.println("the quotient is "+a);
System.out.println("the integral quotient is "+b);
System.out.println("the remainder is "+r);
}
}
3. CHECK IF A STUDENT HAS PASSED IN 3 SUBJECTS:-
(CALCULATING AVERAGE AND CHECKING IF AVERAGE>50%)
import java.io.*;
class result
{
public static void main()throws IOException
{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader (isr);
System.out.println("Enter marks in Maths");
String a = br.readLine();
float p = Float.parseFloat(a);
System.out.println("Enter marks in English");
String b = br.readLine();
float q = Float.parseFloat(b);
System.out.println("Enter marks in Maths");
String c = br.readLine();
float r = Float.parseFloat(c);
float n = (p+q+r)/3;
if (n>=50)
{
System.out.println("you have passed");
}
else
{
System.out.println("you have failed");
}
}
}
4. PRINTING OF EVEN NUMBERS FROM 1 TO 50
import java.io.*;
class even_numbers
{
public static void main()
{
for(int i=2 ; i<=50 ; i=i+2)
{
System.out.print(i+" ");
}
}
}
5. PRINTING OF ODD NUMBERS FROM 1 TO 50
import java.io.*;
class odd_numbers
{
public static void main()
{
InputStreamReader isr = new InputStreamReader(System.in);
for(int i=1 ; i<=50 ; i=i+2)
{
System.out.println(i);
}
}
}
No comments:
Post a Comment