Programs for beginners class IX
Write a menu driven program using switch case statement that outputs the results of the following evaluation based on the number entered by the user
Programs for beginners class IX
loops
Write a menu driven program using switch case statement that outputs the results of the following evaluation based on the number entered by the user
- Maximum of the two numbers
- Absolute value of the number
- Square root of the number
- Random numbers
import java.util.*;
class MathFunctions
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number");
int n=sc.nextInt();
switch(n)
{
case 1:
System.out.println("Enter two numbers");
int a=sc.nextInt(); int b=sc.nextInt();
System.out.println("The biggest nmber is"+Math.max(a,b));
break;
case 2:
System.out.println("Enter a number");
int c=sc.nextInt();
System.out.println("The absolute values is"+Math.abs(c));
break;
case 3:
System.out.println("Enter a number");
int d=sc.nextInt();
System.out.println("The SQRT is"+Math.sqrt(d)); break;
case 4:
System.out.println("The random number is"+Math.random());
break;
default:
System.out.println("Enter a number between 1 to 4");
break;
}
}
}
Write a program to find the sum of the following series.
sum=1+4+9+16+……….100
sum= 2+4+6+8+……..n
import java.util.*;
class Series
{
public static void main()
{
int sum=0;
for(int i=1;i<=10;i++)
{
int q=i*i;
sum=sum+q;
}
System.out.println("The sum of the series1 is+sum);
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number");
int n=sc.nextInt();
float sum1=0.0f;
for(int i=2;i<=n;i+=2)
{
sum1=sum1+i;
}
System.out.println("The sum of the series2 is "+sum1);
}
}Write a program to print of the following series.
1 3 5 7 9
30 25 20 15 10
class Series
{
public static void main()
{
for(int i=1;i<=9;i+=2)
{
System.out.print(i + " ");
}
System.out.println();
for(int i=30;i>=10;i-=5)
{
System.out.print(i+ " ");
}
}
}
A computer salesman gets commission on the following basis:
Write a program to accept the sales as input, calculate and print his commission amount and rate of commission.
<tbody>
Sales
Commission Rate
Rs. 0 - 20,000
3%
Rs. 20,000 - 50,000
12%
Rs. 50,001 and more
31%
</tbody>
/*A computer salesman gets commission on the following basis:
Sales
Commission Rate
Rs. 0 - 20,000
3%
Rs. 20,000 - 50,000
12%
Rs. 50,001 and more
31%
Write a program to accept the sales as input, calculate and print his commission amount and rate of commission.
*/
import java.util.*;
class Commision
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the sales amount");
int saleAmt=sc.nextInt();
int comRate=0;
float commision=0.0f;
if(saleAmt>0 && saleAmt<20000)
comRate=3;
else if(saleAmt >= 20000 && saleAmt < 50000)
comRate=12;
else
comRate=31;
commision=(comRate*saleAmt)/100;
System.out.println("The sales amount is "+saleAmt);
System.out.println("The commision rate is "+comRate);
System.out.println("The commision is "+commision);
}
}JAVA VIDEOS
Related Posts
Continue learning with these related articles

String Methods in Java for ICSE Class 10: 25 Output Questions with Answers
ICSE Class 10 Computer Applications practice on String class methods: length, charAt, indexOf, lastIndexOf, substring, replace, trim, compareTo, equals and more, with 25 board-style output questions and step-by-step answers.

Special Number Programs in Java for ICSE: Armstrong, Spy, Neon, Disarium, Pronic and More
Every special number asked in ICSE Computer Applications – prime, perfect, Armstrong, palindrome, automorphic, neon, spy, Niven, duck, buzz, Disarium, special and pronic numbers – with definitions, examples and one complete Java program that checks them all.

Math Library Methods in Java for ICSE Class 9 (with Outputs)
ICSE Class 9 Computer Applications notes on the Java Math class: sqrt, cbrt, pow, abs, max, min, ceil, floor, round, rint and random, with return types, tricky negative-number outputs and Java expressions for formulas.