Académique Documents
Professionnel Documents
Culture Documents
note:
The static variable can be used to refer to the common property of all
objects (which is not unique for each object), for example, the company
name of employees, college name of students, etc.
The static variable gets memory only once in the class area at the time of
class loading.
class VariableDemo
count++;
obj2.increment();
class CounterClass{
CounterClass(){
count++;
System.out.println(count);
}
}
*/
class PrimeNumberDemo
int n;
int status = 1;
int num = 3;
System.out.println(2);
for ( int i = 2 ; i <=100 ; )
if ( num%j == 0 )
status = 0;
break;
if ( status != 0 )
System.out.println(num);
i++;
status = 1;
num++;
int i;
int num = 0;
int maxCheck = 100; // maxCheck limit till which you want to find prime
numbers
//Empty String
isPrime = CheckPrime(i);
if (isPrime) {
System.out.println(primeNumbersFound);
int remainder;
remainder = numberToCheck % i;
if (remainder == 0) {
return false;
return true;
import java.util.Scanner;
num = scanner.nextInt();
scanner.close();
temp = num;
while(num > 0)
count++;
while(temp > 0)
{
digit = temp % 10;
count--;
int i,m=0,flag=0;
m=n/2;
if(n==0||n==1){
}else{
for(i=2;i<=m;i++){
if(n%i==0){
flag=1;
break;
}
}//end of else
import java.util.Scanner;
class JavaExample {
double sq = Math.sqrt(x);
* be non-zero.
*/
scanner.close();
if (checkPerfectSquare(num))
else
import java.util.Scanner;
class JavaExample {
public static double squareRoot(int number) {
double temp;
double sr = number / 2;
do {
temp = sr;
return sr;
scanner.close();
import java.util.Scanner;
n1 = scan.nextInt();
n2 = scan.nextInt();
// read numbers one-by-one and generate armstrong.
temp = i;
n = 0;
while(temp != 0)
rem = temp%10;
n = n + rem*rem*rem;
temp = temp/10;
if(i == n)
if(count == 0)
count++;
}
if(count == 0)
int x, i = 1 ;
int sum = 0;
x = s.nextInt();
while(i <= x)
{
i++;
import java.util.*;
class PosNegZero
int num;
num=sc.nextInt();
//check condition for +ve, -ve and Zero
if(num>0)
else if(num<0)
else
System.out.println("IT's ZERO.");
import java.util.*;
class RandomNumbers {
int c;
System.out.println(t.nextInt(100));
}
}
class ArmstrongExample{
int c=0,a,temp;
temp=n;
while(n>0)
a=n%10;
n=n/10;
c=c+(a*a*a);
if(temp==c)
System.out.println("armstrong number");
else
gcd = i;
import java.util.Scanner;
class Largest
{
int x, y, z;
x = in.nextInt();
y = in.nextInt();
z = in.nextInt();
else
import java.util.Scanner;
int m, n;
m = s.nextInt();
n = s.nextInt();
m = m ^ n;
n = m ^ n;
m = m ^ n;
System.out.println("After Swapping");
System.out.println("First number:"+m);
System.out.println("Second number:"+n);
import java.util.Scanner;
*/
num1 = scanner.nextInt();
num2 = scanner.nextInt();
num3 = scanner.nextInt();
scanner.close();
*/
import java.util.Scanner;
*/
num1 = scanner.nextInt();
num2 = scanner.nextInt();
num3 = scanner.nextInt();
scanner.close();
*/
import java.util.Scanner;
int n, temp;
n = s.nextInt();
a[i] = s.nextInt();
temp = a[i];
a[i] = a[j];
a[j] = temp;
System.out.println("Second Largest:"+a[n-2]);
System.out.println("Smallest:"+a[0]);
4. Write a java program to add, subtract and multiply two numbers using
object and class considering the following 4 cases
private
class ABC
return a*b;
return a+b;
{
if(a>b)
return a-b;
else
return b-a;
System.out.println(obj.num);
System.out.println(obj.mult(10,20));
System.out.println(obj.add(10,20));
System.out.println(obj.subtract(10,20));
default
package abcpackage;
class ABC {
* be considered as default.
*/
return a+b;}
if(a>b)
return a-b;
else
return b-a;
class ABC1
System.out.println(obj.num);
System.out.println(obj.mult(10,20));
System.out.println(obj.add(10,20));
System.out.println(obj.subtract(10,20));
protected
package abcpackage;
return a+b;
return a*b;
if(a>b)
return a-b;
else
return b-a;
package xyzpackage;
import abcpackage.*;
System.out.println(obj.add(11, 22));
System.out.println(obj.mult(11, 22));
System.out.println(obj.subtract(11, 22));
}
}
public
package abcpackage;
return a+b;
return a*b;
if(a>b)
return a-b;
else
return b-a;
package xyzpackage;
import abcpackage.*;
class Test{
System.out.println(obj.mult(100, 1));
System.out.println(obj.subtract(100, 1));
class Overload
return (x*x*x);
}
double volume(double r, int h) // volume of cylinder
return (3.14519F*r*r*h) ;
return (l*b*h);
class OverloadDemo2
}
}
if(lastIndex == - 1){
} else {
System.out.println(sb);
import java.util.Scanner;
int choice=sc.nextInt();
if(choice==1)
obj.Allahabad();
else if(choice==2)
obj.SBI();
else if(choice==3)
obj.BankOfBaroda();
else if(choice==4)
obj.PNB();
else
package sreeparna
String stName;
int stRoll;
int stId;
School(String schoolName){
this(73); // calls one parameter constructor with int within same class.
School(int s){
this.stName=stName;
this.stRoll=stRoll;
this.stId=stId;
void display(){
package sreeparna;
Student(){
Student(String schoolName){
this();
// Create the object of the class School and passes String value within
double quotes from const.
st.display();