import java.util.*;
class Prog1
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int res,a,b,c;
System.out.print("Enter the values of a b and c ");
a=sc.nextInt();
b=sc.nextInt();
c=sc.nextInt();
res=Math.round((1.0f/(a*a))+(2.0f/(b*b))+(3.0f/(c*c)));
System.out.println("Result = "+res);
}
}
import java.util.*;
class Prog2
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int m;
System.out.print("Enter the values of m (m>1) ");
m=sc.nextInt();
System.out.println((2*m)+", "+(m*m-1)+", "+(m*m+1)+" are Pythagorean Triplet");
}
}
import java.util.*;
class Prog3
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int n;
System.out.print("Enter any number ");
n=sc.nextInt();
System.out.println("Square root of "+n+" = "+Math.round(Math.sqrt(n)));
System.out.println("Cube root of "+n+" = "+Math.round(Math.cbrt(n)));
}
}
import java.util.*;
class Prog4
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
double r,v;
System.out.print("Enter volume of any sphere ");
v=sc.nextDouble();
r=Math.cbrt(v*(3.0/4)*(7.0/22));
System.out.println("Radius = "+r);
}
}
import java.util.*;
class Prog5
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
double a,b,res;
System.out.print("Enter the values of a and b ");
a=sc.nextDouble();
b=sc.nextDouble();
a=a*(22/7*180);
b=b*(22/7*180);
res=(Math.tan(a)-Math.tan(b))/(1+Math.tan(a)*Math.tan(b));
System.out.println("Result = "+res);
}
}
import java.util.*;
class Prog6
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
double a,b,c,disc;
System.out.print("Enter the values of a,b and c ");
a=sc.nextDouble();
b=sc.nextDouble();
c=sc.nextDouble();
disc=Math.pow(b,2)-4*a*c;
System.out.println("Value of Discriminant = "+Math.round(disc));
}
}
import java.io.*;
class Prog1
{
public static void main(String s[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int x,y,z;
System.out.print("Enter First number ");
x=Integer.parseInt(br.readLine());
System.out.print("Enter Second number ");
y=Integer.parseInt(br.readLine());
System.out.print("Enter Third number ");
z=Integer.parseInt(br.readLine());
if(x==y & y==z)
System.out.println("All are equal");
else if(x>y & x>z)
System.out.println("x is greatest");
else if(y>z)
System.out.println("y is greatest");
else
System.out.println("z is greatest");
if(x>=0 & y>=0 & z>=0)
System.out.print("All Positive");
else if(x<0 & y<0 && z<0)
System.out.println("All Negative");
else
System.out.println("Mixed Number");
}
}
import java.util.*;
class Prog2
{
public static void main(String sa[])
{
Scanner sc=new Scanner(System.in);
double s,a,b,c,ar,pr;
System.out.print("Enter three sides of triangle ");
a=sc.nextDouble();
b=sc.nextDouble();
c=sc.nextDouble();
pr=a+b+c;
s=pr/2;
ar=Math.sqrt(s*(s-a)*(s-b)*(s-c));
if(ar==pr)
System.out.println("Equable Triangle");
else
System.out.println("Non Equable Triangle");
}
}
import java.util.*;
class Prog3
{
public static void main(String sa[])
{
Scanner sc=new Scanner(System.in);
int num,sum,prod,gsum,dig1,dig2;
System.out.print("Enter any two digit number ");
num=sc.nextInt();
dig1=num/10;
dig2=num%10;
sum=dig1+dig2;
prod=dig1*dig2;
gsum=sum+prod;
if(gsum==num)
System.out.println("Special Two Digit Number");
else
System.out.println("Not a Special Two Digit Number");
}
}
Condition | Nature |
---|---|
If d>=0 | Roots are real |
If d<0 | Roots are imagenary |
import java.util.*;
class Prog4
{
public static void main(String sa[])
{
Scanner sc=new Scanner(System.in);
double a,b,c,d,r1,r2;
System.out.print("Enter the values of a, b and c for Quadratic Eq ");
a=sc.nextDouble();
b=sc.nextDouble();
c=sc.nextDouble();
d=b*b-4*a*c;
if(d>=0)
{
System.out.println("Roots are real ");
r1=(-b+Math.sqrt(d))/2*a;
r2=(-b-Math.sqrt(d))/2*a;
System.out.println("Root1 = "+r1);
System.out.println("Root2 = "+r2);
}
else
{
System.out.println("Roots are imaginary ");
}
}
}
Distance travelled | Fare |
---|---|
Upto 10 km | Fixed charge Rs 80 |
11 km to 20 km | Rs 6/km |
21 km to 30 km | Rs 5/km |
31 km and above | Rs 4/km |
import java.util.*;
class Prog5
{
public static void main(String sa[])
{
Scanner sc=new Scanner(System.in);
int dist,fare;
System.out.print("Enter the distance covered by passanger ");
dist=sc.nextInt();
if(dist<=10)
fare=80;
else if(dist<=20)
fare=80+(dist-10)*6;
else if(dist<=30)
fare=140+(dist-20)*5;//80+60
else
fare=190+(dist-30)*4;//80+60+50;
System.out.println("Bus Fare = "+fare);
}
}
Marks obtained in different subjects | Stream |
---|---|
English, Math and Science >=80% | Pure Science |
English and Science >=80%, Math >=60% | Bio Science |
English, Math and Science >=60% | Commerce |
import java.util.*;
class Prog6
{
public static void main(String sa[])
{
Scanner sc=new Scanner(System.in);
double em,mm,sm;
System.out.print("Enter the marks in english, maths and science ");
em=sc.nextDouble();
mm=sc.nextDouble();
sm=sc.nextDouble();
if(em>=80 & mm>=80 & sm>=80)
System.out.println("Pure Science");
else if(em>=80 & sm>=80 & mm>=60)
System.out.println("Bio Science");
else if(em>=60 & sm>=60 & mm>=60)
System.out.println("Commerce");
}
}
Term | Rate of interest(general) | Rate of interest(Seniors) |
---|---|---|
Up to 1 year | 7.5% | 8.0% |
Up to 2 years | 8.5% | 9.0% |
Up to 3 years | 9.5% | 10.0% |
More than 3 years | 10.0% | 11.0% |
Amount deposited | Term | Age | Interest earned | Amount paid |
---|---|---|---|---|
XXX | XXX | XXX | XXX | XXX |
import java.util.*;
class Prog7
{
public static void main(String sa[])
{
Scanner sc=new Scanner(System.in);
double p,age,term,rate,intt,amt;
System.out.print("Enter the sum, age and term ");
p=sc.nextDouble();
age=sc.nextDouble();
term=sc.nextDouble();
if(age>=60)
{
if(term<=1)
rate=8.0;
else if(term<=2)
rate=9.0;
else if(term<=3)
rate=10.0;
else
rate=11.0;
}
else
{
if(term<=1)
rate=7.5;
else if(term<=2)
rate=8.5;
else if(term<=3)
rate=9.5;
else
rate=10.0;
}
intt=p*rate*term/100;
amt=p+intt;
System.out.println("AmtDip\tTerm\tAge\tIntErn\tAmt");
System.out.println(p+"\t"+term+"\t"+age+"\t"+intt+"\t"+amt);
}
}
Weight of parcel | Ordinary booking | Express booking |
---|---|---|
Up to 100gm | Rs80 | Rs100 |
101 to 500gm | Rs150 | Rs200 |
501 to 1000gm | Rs210 | Rs250 |
More than 1000gm | Rs250 | Rs300 |
import java.util.*;
class Prog8
{
public static void main(String sa[])
{
Scanner sc=new Scanner(System.in);
char ch;
double wt,charge;
System.out.print("Enter Your choice O/E ");
ch=sc.next().charAt(0);
System.out.print("Enter the weight of parcel ");
wt=sc.nextDouble();
if(ch=='O'||ch=='o')
{
if(wt<=100)
charge=80.0;
else if(wt<=500)
charge=150.0;
else if(wt<=1000)
charge=210.0;
else
charge=250.0;
}
else
{
if(wt<=100)
charge=100.0;
else if(wt<=500)
charge=200.0;
else if(wt<=1000)
charge=250.0;
else
charge=300.0;
}
System.out.println("Charge of Parcel = "+charge);
}
}
import java.util.*;
class Prog9
{
public static void main(String sa[])
{
Scanner sc=new Scanner(System.in);
char ch;
double r,s,l,b,p=3.14,ar;
System.out.println("Menu\nc. Circle\ns.Square\nr.Rectangle");
System.out.print("Enter Your choice ");
ch=sc.next().charAt(0);
switch(ch)
{
case 'c':
System.out.print("Enter the radius of circle ");
r=sc.nextDouble();
ar=p*r*r;
System.out.print("Area of Circle = "+ar);
break;
case 's':
System.out.print("Enter the side of square ");
s=sc.nextDouble();
ar=s*s;
System.out.print("Area of Square = "+ar);
break;
case 'r':
System.out.print("Enter the Length and Breadth of Rectangle ");
l=sc.nextDouble();
b=sc.nextDouble();
ar=l*b;
System.out.print("Area of Rectangle = "+ar);
break;
default:
System.out.println("Wrong choice");
}
}
}
import java.util.*;
class Prog10
{
public static void main(String sa[])
{
Scanner sc=new Scanner(System.in);
int ch;
double r,s,l,b,h,p=22.0/7,v;
System.out.println("Menu\n1. Cube\n2.Sphere\n3.Cuboid");
System.out.print("Enter Your choice ");
ch=sc.nextInt();
switch(ch)
{
case 1:
System.out.print("Enter the side of Cube ");
s=sc.nextDouble();
v=s*s*s;
System.out.print("Volume of Cube = "+v);
break;
case 2:
System.out.print("Enter the radius of Sphere ");
r=sc.nextDouble();
v=(4*p*r*r*r)/3;
System.out.print("Volume of Sphere = "+v);
break;
case 3:
System.out.print("Enter the Length, Breadth & Height of Cuboid ");
l=sc.nextDouble();
b=sc.nextDouble();
h=sc.nextDouble();
v=l*b*h;
System.out.print("Volume of Cuboid = "+v);
break;
default:
System.out.println("Wrong choice");
}
}
}
import java.util.*;
class Prog11
{
public static void main(String sa[])
{
Scanner sc=new Scanner(System.in);
int ch;
double v1,v2,rv=0,l1,l2,t=0;
System.out.print("Enter length and velocity of First Train ");
l1=sc.nextDouble();
v1=sc.nextDouble();
System.out.print("Enter length and velocity of Second Train ");
l2=sc.nextDouble();
v2=sc.nextDouble();
System.out.println("Menu\n1. Same Direction\n2. Opposit Direction");
System.out.print("Enter Your choice ");
ch=sc.nextInt();
switch(ch)
{
case 1:
rv=Math.abs(v1-v2);
t=(l1+l2)/rv;
break;
case 2:
rv=Math.abs(v1+v2);
t=(l1+l2)/rv;
break;
default:
System.out.println("Wrong choice");
}
System.out.println("Relative Velocity = "+rv);
System.out.println("Time Taken to cross each other = "+t);
}
}
No. of years used | Rate of depreciation |
---|---|
1 | 10% |
2 | 20% |
3 | 30% |
4 | 50% |
More than 4 | 60% |
import java.util.*;
class Prog12
{
public static void main(String sa[])
{
Scanner sc=new Scanner(System.in);
int yr;
double oprice,amt,dep;
System.out.print("Enter Years used and original price of car ");
yr=sc.nextInt();
oprice=sc.nextDouble();
switch(yr)
{
case 1:
dep=oprice*0.1;
break;
case 2:
dep=oprice*0.2;
break;
case 3:
dep=oprice*0.3;
break;
case 4:
dep=oprice*0.5;
break;
default:
dep=oprice*0.6;
}
amt=oprice-dep;
System.out.println("Original Price = "+oprice);
System.out.println("Depreciation value = "+dep);
System.out.println("Amount to be paid = "+amt);
}
}
class Prog1_a
{
public static void main(String s[])
{
int i,a,b,c,d;
a=0;
b=1;
c=2;
System.out.print(a+", "+b+", "+c);
for(i=1;i<=7;i++)
{
d=a+b+c;
System.out.print(", "+d);
a=b;
b=c;
c=d;
}
}
}
class Prog1_b
{
public static void main(String s[])
{
int i,j=1;
for(i=1;i<=10;i++)
{
if(i%2==0)
System.out.print(-j+", ");
else
System.out.print(j+", ");
j=j+2;
}
}
}
class Prog1_c
{
public static void main(String s[])
{
int i;
for(i=1;i<=10;i++)
{
System.out.print(i*i-1+", ");
}
}
}
class Prog1_d
{
public static void main(String s[])
{
int i,j=0;
for(i=1;i<=10;i++)
{
j=j*10+1;
System.out.print(j+", ");
}
}
}
class prog1_e
{
public static void main(String s[])
{
int i,j=0;
for(i=1;i<=10;i++)
{
j=j*10+i;
System.out.print(j+", ");
}
}
}
import java.util.*;
class Prog2_a
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int i,n,sum,a,b,c;
System.out.print("Enter the no. of terms ");
n=sc.nextInt();
a=1;
b=1;
sum=a+b;
for(i=1;i<=n-2;i++)
{
c=a+b;
sum+=c;
a=b;
b=c;
}
System.out.print("Sum of series = "+sum);
}
}
import java.util.*;
class Prog2_b
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int i,n,sum=0;
System.out.print("Enter the no. of terms ");
n=sc.nextInt();
for(i=2;i<=n*2;i+=2)
{
if(i%4==0)
sum-=i;
else
sum+=i;
}
System.out.print("Sum of series = "+sum);
}
}
import java.util.*;
class Prog2_c
{
public static void main(String sa[])
{
Scanner sc=new Scanner(System.in);
int i,n,sum=0,j=0;
System.out.print("Enter the no. of terms ");
n=sc.nextInt();
for(i=1;i<=n;i++)
{
j=j+i;
sum=sum+j;
}
System.out.print("Sum of series = "+sum);
}
}
import java.util.*;
class Prog2_d
{
public static void main(String sa[])
{
Scanner sc=new Scanner(System.in);
int i,n,sum=0,j=1;
System.out.print("Enter the no. of terms ");
n=sc.nextInt();
for(i=1;i<=n;i++)
{
j=j*i;
sum=sum+j;
}
System.out.print("Sum of series = "+sum);
}
}
import java.util.*;
class Prog2_e
{
public static void main(String sa[])
{
Scanner sc=new Scanner(System.in);
int n,i;
float sum=0,s=0,p=1;
System.out.print("Enter the no. of terms ");
n=sc.nextInt();
for(i=1;i<=n;i++)
{
p=p*i;
s=s+i;
sum=sum+s/p;
}
System.out.print("Sum of series = "+sum);
}
}
import java.util.*;
class Prog3_a
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int i,a,n,sum=0;
System.out.print("Enter the values of a & n ");
a=sc.nextInt();
n=sc.nextInt();
for(i=1;i<=n;i++)
{
sum+=Math.pow(a,i);
}
System.out.print("Sum of series = "+sum);
}
}
import java.util.*;
class Prog3_b
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int i,a,n,sum=0;
System.out.print("Enter the values of a & n ");
a=sc.nextInt();
n=sc.nextInt();
for(i=1;i<=n;i++)
{
sum+=(a+i);
}
System.out.print("Sum of series = "+sum);
}
}
import java.util.*;
class Prog3_c
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
double i,a,sum=0;
System.out.print("Enter the values of a ");
a=sc.nextDouble();
for(i=2;i<=20;i+=3)
{
sum+=a/i;
}
System.out.print("Sum of series = "+sum);
}
}
import java.util.*;
class Prog3_d
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
double n,i,a,sum=0;
System.out.print("Enter the values of a & n ");
a=sc.nextDouble();
n=sc.nextDouble();
for(i=1;i<=n;i++)
{
sum+=i/Math.pow(a,i);
}
System.out.print("Sum of series = "+sum);
}
}
import java.util.*;
class Prog3_e
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
double n,i,a,sum=0,j=1;
System.out.print("Enter the values of a & n ");
a=sc.nextDouble();
n=sc.nextDouble();
for(i=1;i<=n;i++)
{
if(i%2==0)
sum-=Math.pow(a,j);
else
sum+=Math.pow(a,j);
j+=2;
}
System.out.println("Sum of series = "+sum);
}
}
import java.util.*;
class Prog4
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int x,y,i,hcf=0,m;
System.out.print("Enter the two values ");
x=sc.nextInt();
y=sc.nextInt();
m=Math.min(x,y);
for(i=1;i<=m;i++)
{
if(x%i==0 & y%i==0)
{
hcf=i;
break;
}
}
if(hcf==1)
System.out.println("Co Prime");
else
System.out.println("Non Co Prime");
}
}
import java.util.*;
class Prog5
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int n,r,p=1;
System.out.print("Enter the number ");
n=sc.nextInt();
while(n>0)
{
r=n%10;
if(r%2==0)
{
p*=(r+1);
}
n=n/10;
}
System.out.println("product is "+p);
}
}
import java.util.*;
class Prog6_
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int n,i,flag=0;
System.out.print("Enter the number ");
n=sc.nextInt();
for(i=1;i<n/2;i++)
{
if((i*(i+1))==n)
{
flag=1;
System.out.println("Pronic Number");
break;
}
}
if(flag==0)
System.out.println("Non Pronic Number");
}
}
import java.util.*;
class Prog7
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int mm,n,i,flag=0,org,rev=0,r;
System.out.print("Enter the number ");
n=sc.nextInt();
org=n;
while(n>0)
{
r=n%10;
n=n/10;
rev=rev*10+r;
}
mm=Math.min(org,rev);
for(i=2;i<mm/2;i++)
{
if(org%i==0 || rev%i==0)
{
flag=1;
System.out.println("Not a Twisted Prime Number");
break;
}
}
if(flag==0)
System.out.println("Twisted Prime Number");
}
}
import java.util.*;
class Prog8
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int n,i,flag=0,j;
System.out.print("Enter the number ");
n=sc.nextInt();
for(i=2;i<=n/2;i++)
{
if(n%i==0)
{
flag=1;
break;
}
}
if(flag==0)
System.out.println("Prime Number");
else
{
i=n+1;
while(true)
{
flag=0;
for(j=2;j<=i/2;j++)
{
if(i%j==0)
{
flag=1;
break;
}
}
if(flag==0)
{
System.out.println("Next Prime Number = "+i);
break;
}
i++;
}
}
}
}
import java.util.*;
class Prog9_116
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int n,dig,flag=0;
System.out.print("Enter the number ");
n=sc.nextInt();
while(n>0)
{
dig=n%10;
n=n/10;
if(dig==0)
{
flag=1;
break;
}
}
if(flag==0)
System.out.println("Not a Duck Number");
else
System.out.println("Duck Number");
}
}
import java.util.*;
class Prog10
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int run,balls=0,total_runs=0;
do
{
System.out.print("Enter the runs ");
run=sc.nextInt();
if(run!=-1)
total_runs+=run;
balls++;
}while(run!=-1);
System.out.println("Number of Balls = "+balls);
System.out.println("Total Number of runs made = "+total_runs);
}
}
Distance (in km) | Charges |
---|---|
First 5 km | Rs 80 |
Next 10 km | Rs 10/km |
More than 15 km | Rs 8/km |
import java.util.*;
class Prog11
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int fare,t_Fare=0,nop=0,dist;
char ch;
do
{
System.out.print("Enter the Distance ");
dist=sc.nextInt();
if(dist<=5)
fare=80;
else if(dist<=15)
fare=(dist-5)*10+80;
else
fare=(dist-15)*8+180;
t_Fare+=fare;
nop++;
System.out.println("Total Distance = "+dist);
System.out.println("Total Fare to be paid = "+fare);
System.out.println("More Passenger ");
ch=sc.next().charAt(0);
}while(ch=='y'||ch=='Y');
System.out.println("Total Number of Passengers = "+nop);
System.out.println("Total Fare received = "+t_Fare);
}
}
import java.util.*;
class Prog12
{
public static void main(String sa[])
{
Scanner sc=new Scanner(System.in);
int num,sum,prod,gsum,dig1,dig2;
System.out.print("Enter any two digit number ");
num=sc.nextInt();
dig1=num/10;
dig2=num%10;
sum=dig1+dig2;
prod=dig1*dig2;
gsum=sum+prod;
if(gsum==num)
System.out.println("Special Two Digit Number");
else
System.out.println("Not a Special Two Digit Number");
}
}
import java.util.*;
class Prog13_116
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int n,r,sum=0,org;
System.out.print("Enter the number ");
n=sc.nextInt();
org=n;
while(n>0)
{
r=n%10;
n=n/10;
sum+=r;
}
if(org%sum==0)
System.out.println("Niven Number");
else
System.out.println("not a Niven Number");
}
}
import java.util.*;
class Prog14_116
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int n,r,sum=0,prod=1;
System.out.print("Enter the number ");
n=sc.nextInt();
while(n>0)
{
r=n%10;
n=n/10;
sum+=r;
prod*=r;
}
if(sum==prod)
System.out.println("Spy Number");
else
System.out.println("not a Spy Number");
}
}
Process | Result | Counter |
---|---|---|
5 - 2 | 3 | 1 |
3 - 2 | 1 | 2 |
import java.util.*;
class Prog15
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int m,n,i,min,max,ch,d,cnt=0,prod=0;
System.out.print("Enter the values of m and n ");
m=sc.nextInt();
n=sc.nextInt();
min=Math.min(m,n);
max=Math.max(m,n);
System.out.println("Menu\n1.Product\n2.Divide");
System.out.println("Enter the choice ");
ch=sc.nextInt();
switch(ch)
{
case 1:
for(i=1;i<=min;i++)
{
prod+=max;
}
System.out.println("Product is "+prod);
break;
case 2:
do
{
d=max-min;
max=d;
cnt++;
}while(max>=min);
System.out.println("Quotient is "+cnt);
System.out.println("Remainder is "+d);
break;
default:
System.out.println("Sorry");
}
}
}
import java.util.*;
class Prog16
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int a,b,c,sum=0,i,ch;
System.out.println("Menu\n1. Fibonacci Series\n2. Sum of Digits");
System.out.print("Enter your choice ");
ch=sc.nextInt();
switch(ch)
{
case 1:
a=0;b=1;
System.out.print(a+", "+b);
for(i=1;i<=8;i++)
{
c=a+b;
System.out.print(", "+c);
a=b;
b=c;
}
break;
case 2:
System.out.print("Enter the number ");
a=sc.nextInt();
while(a>0)
{
b=a%10;
a=a/10;
sum+=b;
}
System.out.println("Sum of digits = "+sum);
break;
default:
System.out.println("Sorry");
}
}
}
import java.util.*;
class Prog1_a
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
double i,j,k,f,sum=0,n;
System.out.print("Enter the number ");
n=sc.nextDouble();
for(i=1,k=1;i<=n;i+=2,k++)
{
f=1;
for(j=1;j<=k;j++)
{
f*=j;
}
sum=sum+i/f;
}
System.out.println("Sum of series = "+sum);
}
}
import java.util.*;
class Prog1_b
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
double a,i,j,f,sum=0,n;
System.out.print("Enter the values of a and n ");
a=sc.nextDouble();
n=sc.nextDouble();
for(i=1;i<=n;i++)
{
f=1;
for(j=1;j<=i;j++)
{
f*=j;
}
sum=sum+a/f;
}
System.out.println("Sum of series = "+sum);
}
}
import java.util.*;
class Prog1_c
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
double a,i,f=1,sum=0,n;
System.out.print("Enter the values of a and n ");
a=sc.nextDouble();
n=sc.nextDouble();
for(i=1;i<=n;i++)
{
f*=i;
if(i%2==0)
sum=sum-a/f;
else
sum=sum+a/f;
}
System.out.println("Sum of series = "+sum);
}
}
import java.util.*;
class Prog1_d
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
double a,i,f=1,sum=0;
System.out.print("Enter the values of a ");
a=sc.nextDouble();
for(i=2;i<=10;i++)
{
f*=i;
if(i%2==0)
sum=sum+a/f;
else
sum=sum-a/f;
}
System.out.println("Sum of series = "+sum);
}
}
import java.util.*;
class Prog1_e
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int a,i,n,p=2,j,flag;
double sum=0;
System.out.print("Enter the values of a & n ");
a=sc.nextInt();
n=sc.nextInt();
for(i=1;i<=n;i++)
{
for(;;p++)
{
flag=0;
for(j=2;j<=p/2;j++)
{
if(p%j==0)
{
flag=1;
break;
}
}
if(flag==0)
{
sum=sum+p/Math.pow(a,i);
p++;
break;
}
}
}
System.out.println("Sum of series = "+sum);
}
}
import java.util.*;
class Prog2
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int x,y,d,flag=0,max,i;
System.out.print("Enter the two numbers ");
x=sc.nextInt();
y=sc.nextInt();
d=Math.abs(x-y);
if(d==2)
{
max=Math.max(x,y);
for(i=2;i<=max/2;i++)
{
if(x%i==0 || y%i==0)
{
flag=1;
break;
}
}
if(flag==0)
{
System.out.println("Twin Prime Nos");
}
else
{
System.out.println("Non Twin Prime");
}
}
else
{
System.out.println("Non Twin Prime");
}
}
}
class Prog3
{
public static void main(String s[])
{
int i,n,flag,r;
for(i=101;i<200;i++)
{
flag=0;
n=i;
while(n>0)
{
r=n%10;
if(r==0)
{
flag=1;
break;
}
n=n/10;
}
if(flag==0)
{
System.out.println(i);
}
}
}
}
class Prog4
{
public static void main(String s[])
{
int j,i,n,org,flag,r,rev;
for(i=10;i<1000;i++)
{
n=i;
org=i;
rev=0;
while(n>0)
{
r=n%10;
n=n/10;
rev=rev*10+r;
}
if(org==rev)
{
flag=0;
for(j=2;j<=i/2;j++)
{
if(i%j==0)
{
flag=1;
break;
}
}
if(flag==0)
{
System.out.println(i);
}
}
}
}
}
import java.util.*;
class Prog5
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int i,n;
float mm,ms,me,avg;
String name;
System.out.print("Enter the number of students appeared ");
n=sc.nextInt();
for(i=1;i<=n;i++)
{
System.out.print("Enter your name ");
name=sc.next();
System.out.print("Enter the marks in three subjects ");
mm=sc.nextFloat();
ms=sc.nextFloat();
me=sc.nextFloat();
avg=(mm+ms+me)/3;
System.out.println("Name : "+name);
System.out.println("Average : "+avg);
}
}
}
import java.util.*;
class Prog6
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int i,n,r,org;;
System.out.print("Enter any number ");
n=sc.nextInt();
org=n;
for(i=0;i<=9;i++)
{
while(n>0)
{
r=n%10;
if(r==i)
System.out.print(r);
n=n/10;
}
n=org;
}
}
}
import java.util.*;
class Prog7
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int i,n,r,sum;
System.out.print("Enter any number ");
n=sc.nextInt();
do
{
sum=0;
while(n>0)
{
r=n%10;
sum=sum+r;
n=n/10;
}
n=sum;
}while(n>9);
if(sum==1)
System.out.println("Magic no.");
else
System.out.println("Not a magic number");
}
}
import java.util.*;
class Prog8
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int n,r,sum,org;
System.out.print("Enter any number ");
n=sc.nextInt();
do
{
org=n;
sum=0;
while(n>0)
{
r=n%10;
sum=sum+r;
n=n/10;
}
n=org/sum;
if(org%sum!=0)
break;
}while(n<9);
if(n<=9)
System.out.println("Multiple Harshad no.");
else
System.out.println("Not a Multiple Harshad no.");
}
}
class Prog9a
{
public static void main(String s[])
{
int i,j;
for(i=1;i<=9;i+=2)
{
for(j=i;j>=1;j-=2)
System.out.print(j+" ");
System.out.println();
}
}
}
class Prog9b
{
public static void main(String s[])
{
int i,j,k=1;
for(i=5;i>=1;i--)
{
for(j=1;j<=i;j++)
{
System.out.print(k+"\t");
k++;
}
System.out.println();
}
}
}
class Prog9c
{
public static void main(String s[])
{
int i,j,k=15;
for(i=5;i>=1;i--)
{
for(j=1;j<=i;j++)
{
System.out.print(k+"\t");
k--;
}
System.out.println();
}
}
}
class Prog9d
{
public static void main(String s[])
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
if(j%2==0)
System.out.print("0 ");
else
System.out.print("1 ");
}
System.out.println();
}
}
}
class Prog9e
{
public static void main(String s[])
{
int i,j;
for(i=5;i>=1;i--)
{
for(j=5;j>i;j--)
System.out.print(" ");
for(j=1;j<=i;j++)
System.out.print(i+" ");
System.out.println();
}
}
}
class Prog9f
{
public static void main(String s[])
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
System.out.print(i+" ");
for(j=i+1;j<=5;j++)
System.out.print(j+" ");
System.out.println();
}
}
}
class Prog9g
{
public static void main(String s[])
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
if(j%2==0)
System.out.print("# ");
else
System.out.print("* ");
}
System.out.println();
}
}
}
class Prog9h
{
public static void main(String s[])
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=5;j>=i;j--)
System.out.print(j+" ");
System.out.println();
}
}
}
class Prog9h
{
public static void main(String s[])
{
int i,j,k=1;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
System.out.print(k+"\t");
k++;
}
System.out.println();
}
}
}
Example 1: | Example 2: |
---|---|
Input: Type 1 for a triangle and Type 2 for inverted triangle Enter your choice 1 Enter the number of terms 5 | Input: Type 1 for a triangle and Type 2 for inverted triangle Enter your choice 2 Enter the number of terms 6 |
Sample output: 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 | Sample output: 6 6 6 6 6 6 5 5 5 5 5 4 4 4 4 3 3 3 2 2 1 |
import java.util.*;
class Prog10
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int i,j,ch;
System.out.println("Menu\n1.Triangle\n2.Inverted Triangle");
System.out.println("Enter your choice ");
ch=sc.nextInt();
switch(ch)
{
case 1:
for(i=1;i<=5;i++)//row
{
for(j=1;j<=i;j++)
{
System.out.print(i+" ");
}
System.out.println();
}
break;
case 2:
for(i=6;i>=1;i--)//row
{
for(j=1;j<=i;j++)
{
System.out.print(i+" ");
}
System.out.println();
}
break;
default:
System.out.println("Wrong choice");
}
}
}
import java.util.*;
class Prog11
{
public static void main(String s[])
{
Scanner ob=new Scanner(System.in);
int ch,i,j,k=1;
String str;
System.out.println("Menu:\n1.Floyd's Triangle\n2.String Triangle");
System.out.println("Enter your choice");
ch=ob.nextInt();
switch(ch)
{
case 1:
for(i=1;i<=5;i++)//row
{
for(j=1;j<=i;j++)
{
System.out.print(k+"\t");
k++;
}
System.out.println();
}
break;
case 2:
System.out.print("Enter any string ");
str=ob.next();
for(i=0;i<str.length();i++)
{
for(j=0;j<=i;j++)
{
System.out.print(" "+str.charAt(j));
}
System.out.println();
}
break;
default:
System.out.println("Wrong choice");
}
}
}
import java.util.*;
class Prog1
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
char ch,nwchr;
System.out.print("Enter the character ");
ch=sc.next().charAt(0);
nwchr=(char)(ch+10);
System.out.println("10th character = "+nwchr);
}
}
import java.util.*;
class Prog2
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
char ch;
int i;
System.out.print("Enter the character ");
ch=sc.next().charAt(0);
for(i=1;i<=5;i++)
System.out.print((char)(ch+i)+",");
}
}
class Prog3
{
public static void main(String s[])
{
for(int i=65;i<=90;i+=2)
System.out.print((char)i+",");
}
}
import java.util.*;
class Prog4
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
char ch;
int i,cntc=0,cntv=0;
for(i=1;i<=20;i++)
{
System.out.print("Enter the character ");
ch=sc.next().charAt(0);
ch=Character.toUpperCase(ch);
switch(ch)
{
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
cntv++;
break;
default:
cntc++;
}
}
System.out.println("No. of Vowels = "+cntv);
System.out.print("No. of Consonants = "+cntc);
}
}
import java.util.*;
class Prog5
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int num;
char ch;
System.out.print("Enter any number(0<n<27) ");
num=sc.nextInt();
ch=(char)(64+num);
System.out.print("Equivalent Character = "+ch);
}
}
import java.util.*;
class Ex6_162
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int d;
char ch1,ch2;
System.out.print("Enter two characters ");
ch1=sc.next().charAt(0);
ch2=sc.next().charAt(0);
d=ch1-ch2;
if(d==0)
System.out.println("Both characters are same");
else if(d<0)
System.out.println("First character is smaller");
else
System.out.println("Second character is smaller");
}
}
import java.util.*;
class Prog7
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
String str;
int i,sum=0,prod=1,num;
for(i=1;i<=10;i++)
{
System.out.print("Enter number ");
num=sc.nextInt();
sum+=num;
prod*=num;
}
str=Integer.toString(sum)+Integer.toString(prod);
System.out.println("Content(after concatenation) = "+str);
}
}
import java.util.*;
class Prog8
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int ch,i;
System.out.println("Menu\n1. Z to A\n2. a to z");
System.out.print("Enter your choice ");
ch=sc.nextInt();
switch(ch)
{
case 1:
for(i=90;i>=65;i--)
System.out.print((char)i+",");
break;
case 2:
for(i=97;i<=122;i++)
System.out.print((char)i+",");
break;
default:
System.out.println("Wrong choice");
}
}
}
import java.util.*;
class Prog9
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
char ch;
int ascii,rev=0,r;
System.out.print("Enter any character ");
ch=sc.next().charAt(0);
ascii=(int)ch;
while(ascii>0)
{
r=ascii%10;
rev=rev*10+r;
ascii=ascii/10;
}
System.out.print("Equivalent character = "+(char)rev);
}
}
import java.util.*;
class Prog10
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int ch,i;
System.out.println("Menu\n1. I 5 UpperCase \n2. Last 5 LowerCase");
System.out.print("Enter your choice ");
ch=sc.nextInt();
switch(ch)
{
case 1:
for(i=65;i<70;i++)
System.out.print((char)i+",");
break;
case 2:
for(i=118;i<=122;i++)
System.out.print((char)i+",");
break;
default:
System.out.println("Wrong choice");
}
}
}
class Prog11a
{
public static void main(String s[])
{
int i,j;
for(i=1;i<=5;i++)//row
{
for(j=1;j<=i;j++)//col
{
if(i%2!=0)
System.out.print((char)(64+j));
else
System.out.print((char)(96+j));
}
System.out.println();
}
}
}
class Prog11b
{
public static void main(String s[])
{
int i,j;
for(i=5;i>=1;i--)//row
{
for(j=1;j<=i;j++)//col
{
System.out.print((char)(91-j));
}
System.out.println();
}
}
}
class Prog11c
{
public static void main(String s[])
{
int i,j;
for(i=5;i>=1;i-=2)//row
{
for(j=1;j<=i;j++)//col
{
System.out.print((char)(64+j));
}
System.out.println();
}
}
}
class Prog11d
{
public static void main(String s[])
{
int i,j;
for(i=4;i>=1;i--)//row
{
for(j=1;j<=2*i;j+=2)//col
{
System.out.print((char)(79+j));
}
System.out.println();
}
}
}
class Prog11e
{
public static void main(String s[])
{
int i,j;
for(i=5;i>=1;i--)//row
{
for(j=1;j<=i;j++)//col
{
System.out.print((char)(64+j)+"*");
}
System.out.println();
}
}
}
class Prog11f
{
public static void main(String s[])
{
int i,j;
for(i=1;i<=4;i++)//row
{
for(j=1;j<=5;j++)//col
{
if(i<=2)
System.out.print((char)(96+i));
else
System.out.print((char)(62+i));
}
System.out.println();
}
}
}
import java.util.*;
class Prog1
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int arr[]=new int[20];
int i,sume=0,sumo=0;
for(i=0;i<20;i++)
{
System.out.print("Enter the number ");
arr[i]=sc.nextInt();
}
for(i=0;i<20;i++)
{
if(arr[i]%2==0)
sume+=arr[i];
else
sumo+=arr[i];
}
System.out.println("Sum of even numbers "+sume);
System.out.println("Sum of odd numbers "+sumo);
}
}
import java.util.*;
class Prog2
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
float fah[]=new float[20];
float cel;
int i;
for(i=0;i<20;i++)
{
System.out.print("Enter temp in fah ");
fah[i]=sc.nextFloat();
}
for(i=0;i<20;i++)
{
cel=((fah[i]-32)*5)/9;
System.out.println("Converted Temp in Cel "+cel);
}
}
}
n[0] | n[1] | n[2] | n[3] | n[4] | n[5] | n[6] | n[7] | n[8] | n[9] |
15 | 21 | -32 | -41 | 54 | 61 | 71 | -19 | -44 | 52 |
import java.util.*;
class Prog3
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int arr[]=new int[10];
int i;
for(i=0;i<10;i++)
{
System.out.print("Enter element ");
arr[i]=sc.nextInt();
}
for(i=0;i<10;i++)
{
if(arr[i]<0)
System.out.print(arr[i]+", ");
}
for(i=0;i<10;i++)
{
if(arr[i]>=0)
System.out.print(arr[i]+", ");
}
}
}
n[0] | n[1] | n[2] | n[3] | n[4] | n[5] | n[6] | n[7] | n[8] | n[9] |
45 | 65 | 77 | 71 | 90 | 67 | 82 | 19 | 31 | 32 |
import java.util.*;
class Prog4
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int arr[]=new int[20];
int i,j,flag;
for(i=0;i<20;i++)
{
System.out.print("Enter element ");
arr[i]=sc.nextInt();
}
for(i=0;i<20;i++)
{
flag=0;
for(j=2;j<=arr[i]/2;j++)
{
if(arr[i]%j==0)
{
flag=1;
break;
}
}
if(flag==0)
System.out.print(arr[i]+", ");
}
}
}
import java.util.*;
class Prog5
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int n;
System.out.println("Enter the number of students ");
n=sc.nextInt();
float m[]=new float[n];
String name[]=new String[n];
float tot=0,avg,dev;
int i;
for(i=0;i<n;i++)
{
System.out.print("Enter the name and marks ");
name[i]=sc.next();
m[i]=sc.nextFloat();
tot+=m[i];
}
avg=tot/n;
System.out.println("Average marks of all students "+avg);
for(i=0;i<n;i++)
{
System.out.println("Deviation in marks with average "+(m[i]-avg));
}
}
}
Name | Marks |
---|---|
................... | ..................... |
................... | ......................... |
.................... | ....................... |
import java.util.*;
class Prog6
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
float m[]=new float[50];
String name[]=new String[50];
float tot,avg=0,max;
String tName="";
int i;
for(i=0;i<50;i++)
{
System.out.print("Enter the name and marks ");
name[i]=sc.next();
m[i]=sc.nextFloat();
}
max=m[0];
tot=m[0];
tName=name[0];
for(i=1;i<50;i++)
{
tot+=m[i];
if(max<m[i])
{
max=m[i];
tName=name[i];
}
}
avg=tot/50;
System.out.println("Average marks of all students "+avg);
System.out.println(tName+" Scored Highest Marks = "+max);
}
}
Percentage marks | Grade |
---|---|
From 80 to 100 | A |
From 60 to 79 | B |
From 40 to 59 | C |
Less 40 | D |
import java.util.*;
class Prog7
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int rn[]=new int[100];
float m[][]=new float[100][6];
String name[]=new String[100];
float tot,per;
int i,j;
for(i=0;i<100;i++)
{
System.out.print("Enter the rn & name ");
rn[i]=sc.nextInt();
name[i]=sc.next();
for(j=0;j<6;j++)
{
System.out.println("Enter the marks ");
m[i][j]=sc.nextFloat();
}
}
for(i=0;i<100;i++)
{
tot=0;
for(j=0;j<6;j++)
{
tot+=m[i][j];
}
per=tot/6;
System.out.println("Your percentage of marks = "+per);
if(per>=80)
System.out.println("Grade A");
else if(per>=60)
System.out.println("Grade B");
else if(per>=40)
System.out.println("Grade C");
else
System.out.println("Grade D");
}
}
}
import java.util.*;
class Prog8
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int arr[]=new int[20];
int temp,i,k;
for(i=0;i<20;i++)
{
System.out.print("Enter the number ");
arr[i]=sc.nextInt();
}
for(k=1;k<10;k++)//Passes
{
for(i=0;i<10-k;i++)//Steps
{
if(arr[i]>arr[i+1])
{
temp=arr[i];
arr[i]=arr[i+1];
arr[i+1]=temp;
}
}
}
for(k=1;k<10;k++)//Passes
{
for(i=10;i<20-k;i++)//Steps
{
if(arr[i]<arr[i+1])
{
temp=arr[i];
arr[i]=arr[i+1];
arr[i+1]=temp;
}
}
}
for(i=0;i<20;i++)
System.out.println(arr[i]);
}
}
import java.util.*;
class Prog9
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
float me[]=new float[40];
float ms[]=new float[40];
float mm[]=new float[40];
float tot,avg,se=0,sm=0,ss=0;
int i,j;
for(i=0;i<40;i++)
{
System.out.print("Enter the marks in eng, maths & Sc ");
me[i]=sc.nextFloat();
mm[i]=sc.nextFloat();
ms[i]=sc.nextFloat();
}
for(i=0;i<40;i++)
{
tot=me[i]+mm[i]+ms[i];
avg=tot/3;
System.out.println("Average of student "+avg);
se+=me[i];
sm+=mm[i];
ss+=ms[i];
}
System.out.println("Average of English = "+se/40);
System.out.println("Average of Maths = "+sm/40);
System.out.println("Average of Science = "+ss/40);
}
}
import java.util.*;
class Prog10
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int all[]=new int[20];
int even[]=new int[20];
int odd[]=new int[20];
int i,j=0,k=0;
for(i=0;i<20;i++)
{
System.out.print("Enter element ");
all[i]=sc.nextInt();
}
for(i=0;i<20;i++)
{
if(all[i]%2==0)
{
even[j]=all[i];
j++;
}
else
{
odd[k]=all[i];
k++;
}
}
System.out.println("\nEven Numbers");
for(i=0;i<j;i++)
System.out.print(even[i]+", ");
System.out.println("\nOdd Numbers");
for(i=0;i<k;i++)
System.out.print(odd[i]+", ");
}
}
n[0] | n[1] | n[2] | n[3] | n[4] | n[5] | n[6] | n[7] | n[8] | n[9] |
12 | 45 | 49 | 78 | 64 | 77 | 81 | 99 | 45 | 33 |
import java.util.*;
class Prog11
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int num[]=new int[20];
int i,sq;
double dif,sqr;
for(i=0;i<20;i++)
{
System.out.print("Enter element ");
num[i]=sc.nextInt();
}
for(i=0;i<20;i++)
{
sqr=Math.sqrt(num[i]);
sq=(int)sqr;
dif=sqr-sq;
if(dif==0)
System.out.print(num[i]+", ");
}
}
}
import java.util.*;
class Prog12
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int rn[]=new int[40];
float me[]=new float[40];
float mm[]=new float[40];
float mp[]=new float[40];
float mc[]=new float[40];
int i;
for(i=0;i<40;i++)
{
System.out.print("Enter the rn & marks in (E, P, C, & M) ");
rn[i]=sc.nextInt();
me[i]=sc.nextFloat();
mp[i]=sc.nextFloat();
mc[i]=sc.nextFloat();
mm[i]=sc.nextFloat();
}
for(i=0;i<40;i++)
{
if((me[i]>=35) & ((mp[i]>=35 & mc[i]>=35)||(mp[i]>=35 & mm[i]>=35)||(mm[i]>=35 & mc[i]>=35)))
System.out.println("Promotion is granted to Mr. "+rn[i]);
else
System.out.println("Promotion is Not granted to Mr. "+rn[i]);
}
}
}
import java.util.*;
class Prog13
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
double a[]=new double[10];
int b[]=new int[10];
int i;
for(i=0;i<10;i++)
{
System.out.print("Enter element ");
a[i]=sc.nextDouble();
}
for(i=0;i<;10;i++)
{
b[i]=(int)a[i];
}
for(i=0;i<10;i++)
{
System.out.print(b[i]+", ");
}
}
}
Roll no. | Subject A | Subject B | Subject C |
---|---|---|---|
........ | ........ | ........ | ........ |
........ | ........ | ........ | ........ |
........ | ........ | ........ | ........ |
import java.util.*;
class Prog14
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int rn[]=new int[50];
float m1[]=new float[50];
float m2[]=new float[50];
float m3[]=new float[50];
float avg[]=new float[50];
int i;
for(i=0;i<50;i++)
{
System.out.print("Enter the rn & marks in three subjects ");
rn[i]=sc.nextInt();
m1[i]=sc.nextFloat();
m2[i]=sc.nextFloat();
m3[i]=sc.nextFloat();
}
for(i=0;i<50;i++)
{
avg[i]=(m1[i]+m2[i]+m3[i])/3;
System.out.println("Average of Mr. "+rn[i]+" = "+avg[i]);
}
for(i=0;i<50;i++)
{
if(avg[i]>80)
System.out.println("Average of Mr. "+rn[i]+" is more than 80");
}
for(i=0;i<50;i++)
{
if(avg[i]<80)
System.out.println("Average of Mr. "+rn[i]+" is less than 80");
}
}
}
Input | Input | Output |
---|---|---|
P[] | Q[] | R[] |
4 | 19 | 4 |
6 | 23 | 6 |
1 | 7 | 1 |
2 | 8 | 2 |
3 | 3 | |
10 | 10 | |
19 | ||
23 | ||
7 | ||
8 |
import java.util.*;
class Prog15
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int P[]=new int[6];
int Q[]=new int[4];
int R[]=new int[10];
int i,j=0;
System.out.println("For Array P ");
for(i=0;i<6;i++)
{
System.out.print("Enter element ");
P[i]=sc.nextInt();
}
System.out.println("For Array Q ");
for(i=0;i<4;i++)
{
System.out.print("Enter element ");
Q[i]=sc.nextInt();
}
for(i=0;i<10;i++)
{
if(i<P.length)
R[i]=P[i];
else
{
R[i]=Q[j];
j++;
}
}
for(i=0;i<10;i++)
{
System.out.print(R[i]+",");
}
}
}
n[0] | n[1] | n[2] | n[3] | n[4] | n[5] | n[6] | n[7] | n[8] | n[9] |
1982 | 1987 | 1993 | 1996 | 1999 | 2003 | 2006 | 2007 | 2009 | 2010 |
import java.util.*;
class Prog16
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int yog[]={1982,1987,1993,1996,1999,2003,2006,2007,2009,2010};
int mid,beg,end,year,loc=0;
System.out.print("Enter the Graduation year ");
year=sc.nextInt();
beg=0;
end=9;
while(beg<=end)
{
mid=(beg+end)/2;
if(yog[mid]==year)
{
loc=mid+1;
break;
}
else if(yog[mid]>year)
end=mid-1;
else
beg=mid+1;
}
if(loc==0)
System.out.print("Record does not exist");
else
System.out.println("Record exists");
}
}
Average marks | Remarks |
---|---|
85-100 | Excellent |
75-84 | Distinction |
60-74 | First class |
40-59 | Pass |
less than 40 | Poor |
import java.util.*;
class 17
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int n;
System.out.print("Enter the no. of students ");
n=sc.nextInt();
int rn[]=new int[n];
String name[]=new String[n];
float m1[]=new float[n];
float m2[]=new float[n];
float m3[]=new float[n];
float avg;
int i;
for(i=0;i<n;i++)
{
System.out.print("Enter the rn, name & marks in 3 subjects ");
rn[i]=sc.nextInt();
name[i]=sc.next();
m1[i]=sc.nextFloat();
m2[i]=sc.nextFloat();
m3[i]=sc.nextFloat();
}
for(i=0;i<n;i++)
{
avg=(m1[i]+m2[i]+m3[i])/3;
System.out.println("Roll Number = "+rn[i]);
System.out.println("Name = "+name[i]);
if(avg>=85)
System.out.println("Excellent");
else if(avg>=75)
System.out.println("Distinction");
else if(avg>=60)
System.out.println("First Class");
else if(avg>=40)
System.out.println("Pass");
else
System.out.println("Poor");
}
}
}
12 | 10 | 15 | 17 |
30 | 11 | 32 | 71 |
17 | 14 | 29 | 31 |
41 | 33 | 40 | 51 |
import java.util.*;
class Prog18
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int m[][]=new int[4][4];
int i,j,sum=0,prod=1;
for(i=0;i<4;i++)//row
{
for(j=0;j<4;j++)//col
{
System.out.print("Enter element ");
m[i][j]=sc.nextInt();
}
}
for(i=0;i<4;i++)//row
{
for(j=0;j<4;j++)//col
{
if(m[i][j]%2==0)
sum+=m[i][j];
else
prod*=m[i][j];
}
}
System.out.println("Sum of Even numbers = "+sum);
System.out.println("Product of Odd numbers = "+prod);
}
}
import java.util.*;
class Prog19
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
double sale[][]=new double[5][6];
int i,j;
for(i=0;i<5;i++)//Stores
{
for(j=0;j<6;j++)//Departments
{
System.out.print("Enter Monthly Sale of Store #"+(i+1));
System.out.print("# Deptt #"+(j+1)+"# = ");
sale[i][j]=sc.nextDouble();
}
}
for(i=0;i<5;i++)//Stores
{
for(j=0;j<6;j++)//Departments
{
System.out.print("Monthly Sale of Store #"+(i+1));
System.out.println("# Deptt #"+(j+1)+"# = "+sale[i][j]);
}
}
}
}
import java.util.*;
class Prog21
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
String name[]=new String[40];
int m[][]=new int[40][5];
int i,j,tot=0;
String nm;
for(i=0;i<40;i++)
{
System.out.print("Enter the name ");
name[i]=sc.next();
for(j=0;j<5;j++)
{
System.out.print("Enter Marks ");
m[i][j]=sc.nextInt();
}
}
System.out.print("Enter the name to be searched ");
nm=sc.next();
for(i=0;i<40;i++)
{
if(nm.equalsIgnoreCase(name[i])==true)
{
System.out.println("Name : "+name[i]);
for(j=0;j<5;j++)
{
System.out.println("Marks : "+m[i][j]);
tot+=m[i][j];
}
System.out.println("Total Marks : "+tot);
}
}
}
}
-1 | 0 | 2 |
-3 | -1 | 6 |
4 | 3 | -1 |
-6 | 9 | 4 |
4 | 5 | 0 |
1 | -2 | -3 |
class Prog22
{
public static void main(String s[])
{
int M[][]={{-1,0,2},{-3,-1,6},{4,3,-1}};
int MPN[][]={{-6,9,4},{4,5,0},{1,-2,-3}};
int N[][]=new int[3][3];
int i,j;
System.out.println("Matrix N");
for(i=0;i<3;i++)//row
{
for(j=0;j<3;j++)//col
{
N[i][j]=MPN[i][j]-M[i][j];
System.out.print("\t"+N[i][j]);
}
System.out.println();
}
}
}
import java.util.Scanner;
class Prog1
{
public static void main(String s[])
{
Scanner ob=new Scanner(System.in);
String str;
int i,l,w=0,le=0;
char ch;
System.out.println("Enter a sentence");
str=ob.nextLine();
l=str.length();
for(i=0;i<l;i++)
{
ch=str.charAt(i);
if(Character.isLetter(ch))
le++;
if(ch==' ')
w++;
}
System.out.println("Number of words = "+(w+1));
System.out.println("Number of letters = "+le);
}
}
import java.util.*;
class Prog2
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
String st;
int l,i;
System.out.println("Enter the string in Capital letter ");
st=sc.nextLine();
l=st.length();
for(i=0;i<l;i++)
{
switch(st.charAt(i))
{
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
break;
default:
System.out.print(st.charAt(i));
}
}
}
}
import java.util.*;
class Prog3
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
String st;
int ind1,ind2;
System.out.println("Enter the string");
st=sc.nextLine();
ind1=st.indexOf(' ');
ind2=st.lastIndexOf(' ');
System.out.print(st.charAt(0)+" "+st.charAt(ind1+1)+" "+st.charAt(ind2+1));
}
}
import java.util.*;
class Prog4
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
String st,st1,st2;
int ind;
System.out.println("Enter the string");
st=sc.nextLine();
ind=st.lastIndexOf(' ');
st1=st.substring(0,ind);
st2=st.substring(ind+1);
System.out.print(st2+" "+st1);
}
}
import java.util.*;
class Prog5
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
String str,st="",maxst="";
int max=0,l,i;
System.out.println("Enter the string ");
str=sc.nextLine();
str+=" ";
for(i=0;i<str.length();i++)
{
if(str.charAt(i)!=' ')
{
st+=str.charAt(i);
}
else
{
l=st.length();
if(max<l)
{
max=l;
maxst=st;
}
st="";
}
}
System.out.println("Longest Word = "+maxst);
}
}
program
program
program
program
program
program
program
program
program
program
program
program
program
program
program
program
program
program
program
program