Java Programming Solved Programs Sheet 2 by MCA Scholar's Group
Java Programming Solved Programs Sheet 2 by MCA Scholar's Group
Java Programming Solved Programs Sheet 2 by MCA Scholar's Group
Scholar’s Group ✨
@rushipatil71
{int no=1,even=0;
while(no<=20)
even=even+2;
System.out.println(" "+even);
no++;
}}}
2) W a p to display first 30 odd numbers and display sum of that numbers
import java.util.*;
int no=1,odd=-1,sum=0;
while(no<=30)
odd=odd+2;
System.out.print(" "+odd);
sum=sum+odd;
no++;
}
System.out.println("\nSum of all od numbers "+sum);
import java.util.*;
System.out.println("Enter a Number");
num=sc.nextInt();
while(a<=num)
fact=fact*a;
a=a+1;
}
int num,a=0,sum=0;
System.out.println("Enter a Digit");
num=sc.nextInt();
while(num!=0)
a=num%10;
sum=sum+a;
num=num/10;
}
int num,a=0,b,sum=0;
System.out.println("Enter a Digit");
num=sc.nextInt();
b=num;
while(num!=0){
a=num%10;
sum=(sum*10)+a;
num=num/10;
}
if(b==sum){
else{
}}
int num,a=0,rev=0;
num=sc.nextInt();
while(num!=0)
a=num%10;
rev=(rev*10)+a;
num=num/10;
}
}}
while(fibo<=20)
System.out.print(" "+fibo);
fibo=num1+num2;
num1=num2;
num2=fibo;
}
}}
num=sc.nextInt();
orignal=num;
while(orignal!=0)
rem=orignal%10;
res+=rem*rem*rem;
orignal=orignal/10;
if(res==num){
}else
}}}
9) Write a program of class addition of two numbers by using void method and without void method.
class classaddition{
double sum1=a+b;
return sum1;
obj.add(10,20);
double return1=obj.add(10,20.0);
}}
10) Write a program of class student, accept student rollno, name, three subject marks, mob no and
calculate total, percentage and remark of student as,
import java.util.*;
class studclass{
int stud_rol,s1,s2,s3,stud_mob,total,per;
String stud_name;
void insert()
stud_rol=sc.nextInt();
stud_name=sc.next();
s1=sc.nextInt();
s3=sc.nextInt();
stud_mob=sc.nextInt();
void calculate()
total=s1+s2+s3;
System.out.println("Total of subject:"+total);
void persentage(){
per=total/3;
if(per>=70){
}else{
if(per<=70&&per>=60){
}else{
if(per<60&&per>=50){
}else{
if(per<50&&per>=40){
System.out.println("Student Pass Class");
}else{
System.out.println("Student Faill");
}}}}}
ob.insert();
ob.calculate();
ob.persentage();
}}
11) Write a program to create dmart class with accepting values of product id,name,rate and quantity and
calculate payable amt with discount
3000-2000 =15%
2000-1000=10%
import java.util.*;
int pid,qantity,rate,amount,dis,tot;
String pname;
void input(){
Scanner sc=new Scanner(System.in);
System.out.println("product id=");
pid=sc.nextInt();
System.out.println("product name=");
pname=sc.next();
System.out.println("product qantity=");
qantity=sc.nextInt();
System.out.println("product rate=");
rate=sc.nextInt();
void calculate(){
amount=qantity*rate;
void discount()
if(amount>5000){
dis=(amount*20)/100;}
if(amount<5000&&amount>3000){
dis=(amount*15)/100;}
if(amount<3000&&amount>1000){
dis=(amount*7)/100;}
if(amount<1000){
dis=0;
}
}
void total()
tot=amount-dis;
pd.input();
pd.calculate();
pd.discount();
pd.total();