0% found this document useful (0 votes)
20 views14 pages

Ass 3

Uploaded by

Dharan m
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views14 pages

Ass 3

Uploaded by

Dharan m
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

//4.

print the following series

//2,5,10,17,26,37,…

import java.util.*;

class seqodd

public static void main(String args[])

Scanner sc = new Scanner(System.in);

int num = sc.nextInt();

int start = 2;

int count = 1;

System.out.print(start+" ");

for(int i=3;count<=num - 1;i++)

if(i%2!=0)

start = start+i;

System.out.print(start+" ");

count++;

}
/*******************************************************************************

Q5)Apple per kg=120 orange per kg=100 banana per kg=80

megha got 1.5 kgs of apple 750 grams of banana and 2 kilos of orange

what is the total cost ? apply 1% discount what is cost after discount?

*******************************************************************************/

public class Main

public static void main(String[] args) {

int appleInGm = 120%1000;

int orangeInGm = 100%1000;

int bananaInGm = 80%1000;

int res = ((1500*appleInGm)+(750*orangeInGm)+(2000*bananaInGm))/1000;

System.out.println("Total cost is: "+res);

float s=1,discount;

discount = (s*res)/100;

System.out.println("Discount is: "+discount);

System.out.println("Total cost after discount: "+(res-discount));

}
//Q2

import java.util.*;

public class denom

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int num = sc.nextInt();

int count = 0;

while(num>=100)

num = num - 100;

count++;

while(num>=50)

num = num - 50;

count++;

while(num>=10)

num = num - 10;

count++;

while(num>=5)

{
num = num - 5;

count++;

while(num>=2)

num = num - 2;

count++;

while(num>=1)

num = num - 1;

count++;

System.out.println(count);

}
//Q3

import java.util.Scanner;

public class Num

public static void main(String args[])

Scanner sc=new Scanner(System.in);

int n=sc.nextInt();

int count1=1;

int count2=n-1;

int a=0,b=n;

int flag=0;

for(int i=0;i<n;i++)
{

for(int j=0;j<n+1;j++)

if(flag==0)

if(j==n){

System.out.print(count2+" ");

flag=1;

break;

else{

System.out.print(count1+" ");

else

if(j==n)

System.out.print(count2+" ");

flag=0;

break;

else

System.out.print(count1+" ");
}

count1=count1+1;

count2=count2+1;

System.out.println();

}
//1

import java.util.*;

class BestMobilePlan

void printPlanDetails(int day,int night,int weekend)

float dayRemMins = day-100;

float dayMins = dayRemMins*25/100;

//System.out.println(dayMins);

float nigMins = night*15/100;

//System.out.println(nigMins);

float week = weekend*20/100;

//System.out.println(week);

float planA = dayMins+nigMins+week;

System.out.println("Plan A costs: "+planA);

float dayRemMins2 = day-250;

float dayMins2 = dayRemMins2*45/100;

//System.out.println(dayMins2);

float nigMins2 = night*35/100;

//System.out.println(nigMins2);

float week2 = weekend*25/100;

//System.out.println(week2);

float planB = dayMins2+nigMins2+week2;


System.out.println("Plan B costs "+planB);

if(planA<planB)

System.out.println("Plan A is cheapest");

else if(planA>planB)

System.out.println("Plan B is cheapest");

else

System.out.println("Both are same");

class Main extends BestMobilePlan

public static void main(String args[])

Scanner sc = new Scanner(System.in);

int day = sc.nextInt();

int eve = sc.nextInt();

int week = sc.nextInt();

BestMobilePlan bp = new BestMobilePlan();

bp.printPlanDetails(day,eve,week);
}

You might also like