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

If Else Prog

The document contains a series of Java programming exercises that involve inputting values, performing calculations, and using conditional statements. It includes tasks such as calculating discounts based on purchase amounts, determining student performance based on marks, and checking if numbers are positive, negative, even, or odd. Each task is accompanied by example code and expected outputs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views14 pages

If Else Prog

The document contains a series of Java programming exercises that involve inputting values, performing calculations, and using conditional statements. It includes tasks such as calculating discounts based on purchase amounts, determining student performance based on marks, and checking if numbers are positive, negative, even, or odd. Each task is accompanied by example code and expected outputs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

MUST DO GENERAL AND if else if Prog

Q 1. WAP to input purchase amount and calculate and print discount , purchase amount and
payable amount.
as per the following SLABS
purchase amount discount rate
<= 2000 2%
2001 to 5000 5%
>5000 10%

import java.util.*;
public class NINTHDISCOUNT
{
public static void main()
{
Scanner sc= new Scanner(System.in);
System.out.println("Enter purchase amount");
int p= sc.nextInt();
double bill=0.0;
double dis=0.0;
int disrate=0;

if(p>0 && p<=2000)


disrate=2;
else if(p>2000 && p<=5000)
disrate=5;
else
disrate=10;
dis= disrate*p/100.0;

bill=p-dis;
System.out.println(" Your bill is after discount is "+bill);
System.out.println(" discount rate is "+disrate);
System.out.println(" Discount is "+dis+"\n");
}
}

OUTPUT :

Enter purchase amount


2500
Your bill is after discount is 2375.0
discount rate is 5
Discount is 125.0

Q2. WAP to input marks in three subjects ENG, MATHS , COMPUTER . If total is above 75 , print
well done , otherwise print You can always do better . Repeat this for 3 students.(HINT USE
LOOP)

import java.util.*;
class NINTH3
{ public static void main()
{ Scanner sc=new Scanner(System.in);

int i;
for(i=1;i<=3;i++)
{ System.out.println("enter details of roll no "+i);
System.out.println("Enter marks in English");
int a=sc.nextInt();
System.out.println("Enter marks in Maths");
int b=sc.nextInt();
System.out.println("Enter marks in Computer");
int c=sc.nextInt();
int d=a+b+c;
if(d>=75)
System.out.println("you have done well");
else
System.out.println("You can always do better");
}// for
}
}

OUTPUT: ( REPEATING DUE TO LOOP )

enter details of roll no 1


Enter marks in English
45
Enter marks in Maths
78
Enter marks in Computer
93
you have done well
enter details of roll no 2
Enter marks in English
12
Enter marks in Maths
32
Enter marks in Computer
10
You can always do better
enter details of roll no 3
Enter marks in English
40
Enter marks in Maths
34
Enter marks in Computer
56
you have done well

Q3
WAP to input purchase amount and calculate print FREE GIFT
as per the following SLABS
purchase amount free gift

<=1000 wallet
>1000 to 3000 travel bag
>3000 discount coupon

import java.util.*;

public class NINTHGIFTIFELSE


{
public static void main()
{
Scanner sc= new Scanner(System.in);

System.out.println("Enter Purchase amount");

int pa= sc.nextInt();

if(pa>0 && pa<=1000)

System.out.println("Your free gift is a wallet");

else if (pa>1000 && pa<=3000)


System.out.println("Your free gift is a travel bag");

else //if (pa>3000)

System.out.println("Your free gift is a discount coupon");

}
}

OUTPUT :
Enter Purchase amount
2300
Your free gift is a travel bag

Q4.

WAP to input purchase amount and calculate print FREE GIFT


as per the following SLABS

purchase amount free gift

<=1000 wallet
>1000 to 3000 travel bag
>3000 discount coupon

import java.util.*;
public class NINTHIFGIFT
{
public static void main()
{
Scanner sc= new Scanner(System.in);

System.out.println("Enter Purchase amount");

int pa= sc.nextInt();

if(pa>0 && pa<=1000)

System.out.println("Your free gift is a wallet");

if (pa>1000 && pa<=3000)

System.out.println("Your free gift is a travel bag");


if (pa>3000)

System.out.println("Your free gift is a discount coupon");

}
}

OUTPUT:
Enter Purchase amount
6000
Your free gift is a discount coupon

Q5. WAP to input two numbers and interchange them using a third variable.

import java.util.*;
class NINTH2
{
public static void main()//Scanner input
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the value of a");
int a= sc.nextInt();
System.out.println("Enter the value of b");
int b= sc.nextInt();
System.out.println("BEFORE INTERCHANGE");
System.out.println("a is"+a); // 5
System.out.println("b is"+b);//6

int c=a;
a=b;
b=c;

System.out.println("AFTER INTERCHANGE");
System.out.println("a is"+a);
System.out.println("b is"+b);
}
}

OUTPUT:

Enter the value of a


5
Enter the value of b
6
BEFORE INTERCHANGE
a is 5
b is 6
AFTER INTERCHANGE USING THIRD VARIABLE
a is 6
b is 5

Q6. WAP to input two numbers and interchange them WITHOUT using a third variable.

Import java.util.*;
class INTER
{
public static void main()//Scanner input
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the value of a");
int a= sc.nextInt();
System.out.println("Enter the value of b");
int b= sc.nextInt();
System.out.println("BEFORE INTERCHANGE");
System.out.println("a is"+a); // 5
System.out.println("b is"+b);//6

a=a+b; // a 11
b=a-b; // b 11-6 5
a=a-b; // a 11 - 5 6 */

System.out.println("AFTER INTERCHANGE");
System.out.println("a is"+a);
System.out.println("b is"+b);
}
}

OUTPUT:

Enter the value of a


5
Enter the value of b
6
BEFORE INTERCHANGE
a is5
b is6
AFTER INTERCHANGE
a is6
b is5

Q7 WAP to input a number and check and print whether it is a BUZZ number or not.

class buzz
{
public static void main(int n)
{
if(n%10==7 || n%7==0)

System.out.println(n+" is a buzz no");


else
System.out.println(n+" is not a buzz no");

}
}

Output:
Enter a number
17
17 is a buzz no

Q8. WAP to perform the following tasks . Input two numbers and Print their product .
Print a random number. Input two numbers and Print their remainder.

import java.util.*;
public class GENERAL
{
public static void main()
{
Scanner sc= new Scanner(System.in);
System.out.println("Enter A NUMBER");
int A= sc.nextInt();
System.out.println("Enter ANOTHER NUMBER");
int B= sc.nextInt();
int c=A*B;
System.out.println("product is"+c);
double z=Math.random();
System.out.println("A random number is"+z);

System.out.println("Enter A NUMBER");
int G= sc.nextInt();
System.out.println("Enter ANOTHER NUMBER");
int H= sc.nextInt();

int rem=G%H;

System.out.println("REMAINDER IS "+rem);

}}

OUTPUT:
Enter A NUMBER
5
Enter ANOTHER NUMBER
7
product is35
A random number is0.6792341998618988
Enter A NUMBER
21
Enter ANOTHER NUMBER
34
REMAINDER IS 21

VARIABLE DESCRIPTION TABLE

VAR NAME DATATYPE USAGE


A int inputted number
B int inputted number
C int finding product
G int inputted number
H int inputted number
Z double finding random number
rem int finding remainder*/

Q9.
import java.util.*;
public class NINTHaSCII
{

public static void main()


{
Scanner sc= new Scanner (System.in);

System.out.println("Enter an ASCII VALUE");


int a = sc.nextInt();
char c= (char)a;

System.out.println(" Ascii entered is "+a+" Character is "+c);

System.out.println("Enter a character");

char ch=sc.next().charAt(0);

int asc= ch;

System.out.println("Character entered is "+ch+ " Ascii value is "+asc);

}}

OUTPUT :

Enter an ASCII VALUE


65
Ascii entered is 65 Character is A
Enter a character
Z
Character entered is Z Ascii value is 90

Q 10.
WAP to input salary . Calculate print bonus, bonus salary, and payable salary as per the
following
salary bonus rate
<= 50000 3%
>50000 to 100000 6%
>100000 12%

import java.util.*;
class bonus1
{
public static void main()
{
Scanner sc= new Scanner(System.in);
System.out.println("Enter salary");
int salary= sc.nextInt();
double totsal=0.0;
double bon=0.0;
int bonrate=0;
if(salary>0 && salary<=50000)
bonrate=3;
else if(salary >50000 && salary<= 100000)
bonrate=6;
else
bonrate=12;
bon= bonrate*salary/100.0;
totsal=bon+salary;

System.out.println(" Your salary is after bonus is "+totsal);


System.out.println(" bonus rate is "+bonrate);
System.out.println(" bonus is "+bon+"\n");

}
}

Output:

Enter salary
80000
Your salary is after bonus is 84800.0
bonus rate is 6
bonus is 4800.0

Q 11.
WAP to input calls and calculate monthly telephone bill as per the foll
No of calls rate per call(rs)

upto 100 Rs 1 per call


next 200 calls Rs 3 per call
next 300 calls Rs 2 per call
>600 calls Rs 1 per call
A COMPULSORY CHARGE OF RS 50 IS ALSO ADDED TO THE BILL

import java.util.*;
class NINTHbill
{
public static void main()
{
Scanner sc= new Scanner(System.in);
System.out.println("Enter calls");
int c = sc.nextInt();

int bill=0;

if( c<=100)

bill =c*1;

else if (c<=300)

bill = (100*1)+((c-100)*3);

else if (c<=600)

bill= (100*1)+ (200*3)+ ((c-300)*2);


else
bill= (100*1)+ (200*3)+ (300*2)+((c-600)*1);

bill= bill+ 50;

System.out.println("Your bill is "+bill);


}
}

OUTPUT :

Enter calls
350
Your bill is 850

Q 12 . WAP to input principle , rate and time and calculate and print simple interest.

import java.util.*;

class simple
{

public static void main()


{ Scanner sc=new Scanner(System.in);
System.out.println("Enter the principle ");

int p= sc.nextInt();
System.out.println("Enter the rate");
int r= sc.nextInt();
System.out.println("Enter the time");
int t= sc.nextInt();

double simInterest= p*r*t/100.0;


System.out.println("SIMPLE INTEREST IS "+simInterest);

Q13. WAP to input a number and check whether it is a positive or negative number.

import java.util.*;
public class GENR1
{
public static void main()// menu diven program
{ Scanner sc= new Scanner(System.in);
System.out.println("ENTER A NUMBER TO print if it is a negative no");
int n= sc.nextInt();
if(n<0)
System.out.println(n+"is negative no");
else
System.out.println(n+"is positive no");
}
}

Q13. WAP to input a number and check whether it is an even or odd number.

import java.util.*;
public class GENR1
{
public static void main()// menu diven program
{ Scanner sc= new Scanner(System.in);
System.out.println("ENTER A NUMBER TO print if it is a negative no");
int n= sc.nextInt();
if(n%2==0)
System.out.println(n+"is EVEN no");
else
System.out.println(n+"is ODD no");
}
}

You might also like