0% found this document useful (0 votes)
24 views4 pages

Model IT PRACT Material

The document provides 8 examples of Java programs covering topics such as: 1) Performing arithmetic operations on two numbers 2) Calculating percentage of marks and outputting result 3) Finding the largest of three numbers 4) Converting a number to its word representation 5) Checking if a character is a vowel or consonant 6) Printing the first 5 even numbers using a for loop 7) Adding two numbers using a user-defined method 8) Accepting and displaying 5 numbers using an array
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)
24 views4 pages

Model IT PRACT Material

The document provides 8 examples of Java programs covering topics such as: 1) Performing arithmetic operations on two numbers 2) Calculating percentage of marks and outputting result 3) Finding the largest of three numbers 4) Converting a number to its word representation 5) Checking if a character is a vowel or consonant 6) Printing the first 5 even numbers using a for loop 7) Adding two numbers using a user-defined method 8) Accepting and displaying 5 numbers using an array
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/ 4

CLASS 12 – IT PRACTICAL EXAM MATERIAL

JAVA PROGRAMS

1. Write a java program to accept two numbers and perform all four arithmetic operations and
print the result
package calc;
import java.util.Scanner;
public class Calc
{
public static void main(String[] args)
{
int a,b;
Scanner s = new Scanner(System.in);
System.out.println("Enter two numbers ");
a=s.nextInt();
b=s.nextInt();
System.out.println("Addition = "+(a+b));
System.out.println("Subtraction = "+(a-b));
System.out.println("Multiplication = "+(a*b));
System.out.println("Division = "+(a/b));
System.out.println("Remainder = "+(a%b));
}
}

2. Write a java program to accept marks of 5 subjects and calculate percentage and display result
based on the percent scored.
“Good” for percentage>=90
“Average” for percentage between 89 and 60
“Can do better” for percentage between 59 and 40
“Failed” for percentage <40.
package result;
import java.util.Scanner;
public class Result
{
public static void main(String[] args)
{
int m1,m2,m3,m4,m5,per;
Scanner s = new Scanner(System.in);
System.out.println("Enter marks of five subjects ");
m1=s.nextInt();
m2=s.nextInt();
m3=s.nextInt();
m4=s.nextInt();
m5=s.nextInt();
per = (m1+m2+m3+m4+m5)/5;
System.out.println("Percentage = "+per);
if(per>=90)
System.out.println("Good");
else
if(per>=60)
System.out.println("Average");
else
if(per>=40)
System.out.println("Can do better");
else
System.out.println("Fail");
} }

3. Write a java program to print the largest of three numbers.


package calc;
import java.util.Scanner;
public class Lafgest3{
public static void main(String args[])
{
int a,b,c;
Scanner s = new Scanner(System.in);
System.out.println("Enter three numbers ");
a=s.nextInt();
b=s.nextInt();
c=s.nextInt();
if (a>b && a>c)
System.out.println("The largest number is "+ a);
else
if(b>c)
System.out.println("The largest number is "+ b);
else
System.out.println("The largest number is "+ c);
}
}

4. Write a java program to convert number to word


package calc;
import java.util.Scanner;
public class NumberWord{
public static void main(String args[])
{
int a;
Scanner s = new Scanner(System.in);
System.out.println("Enter a number ");
a=s.nextInt();
switch(a)
{
case 1: System.out.println("One"); break;
case 2: System.out.println("Two"); break;
case 3: System.out.println("Three"); break;
case 4: System.out.println("Four"); break;
case 5: System.out.println("Five"); break;
default: System.out.println("Invalid");
}
}
}

5. Write a java program to display if the given character is vowel or consonant


package demo10;
import java.util.Scanner;
public class NewClass {
public static void main(String args[])
{
char c;
Scanner s = new Scanner(System.in);
System.out.println("Enter a character ");
c=s.next().charAt(0);
switch(c)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
System.out.println("It is vowel"); break;
default: System.out.println("It is consonant");
}
}
}

6. Write a java program to print first 5 even numbers using for loop.
package display;
public class EvenNumbers{
public static void main(String args[])
{
for (int i=2; i<=10; i+=2)
System.out.println(i);
}
}

7. Write a java program to add two numbers using a user-defined method.


package display;
public class UserDefinedMethod{
public static int sum(int x, int y)
{
return x+y;
}
public static void main (String[] args)
{
int a=10, b=20;
System.out.println(“Addition of two numbers=”,sum(a,b));
}
}

8. Write a java program to accept 5 numbers from user and display them using an array.

package display;
import java.util.Scanner;
public class Array{
public static void main(String args[])
{
int[] a=new int[5];
int i;
Scanner s = new Scanner(System.in);
System.out.println("Enter any five numbers ");
for(i=0;i<5;i++)
a[i]=s.nextInt();
System.out.println("The entered values are ");
for(i=0;i<5;i++)
System.out.println(a[i]);
}
}

You might also like