Std-12 Java Programming
Std-12 Java Programming
}
6. Java Program to check whether the student is pass or fail.
public class passfail
{
public static void main(String [] args)
{
int marks = 50;
if (marks>=33)
System.out.println("You are Pass.");
else
System.out.println("You are Fail.");
}
}
}
}
12. Java program to check whether entered number is prime or not.
import java.util.Scanner;
class Prime
{
public static void main(String[] args)
{
Scanner sc= new Scanner(System.in);
System.out.println("Enter a number to check if it is truly prime number or not: ");
int number= sc.nextInt();
if(isPrime(number))
{
System.out.println(number + " is prime number");
}
else
{
System.out.println(number + " is a non-prime number");
}
}
static boolean isPrime(int num)
{
if(num<=1)
{
return false;
}
for(int i=2;i<=num/2;i++)
{
if((num%i)==0)
return false;
}
return true;
}
}
13. Java program to print odd number series using while loop.
public class oddseries
{
public static void main(String [] args)
{
int i = 1;
while (i<=30)
{
System.out.println(i);
i = i + 2;
}
}
}
14. Java program to print even number series using For loop.
public class evenseries
{
public static void main(String [] args)
{
for(int i=2; i<=30; i=i+2)
{
System.out.println(i);
}
}
}
{
System.out.print(stringInput.charAt(iStrLength -1));
}
}
21. Java program to find out square root and power of a number.
import java.lang.Math;
public class math
{
public static void main(String [] args)
{
//Square root
double a = 16;
System.out.println("Square Root : " +Math.sqrt(a));
//Power
double b = 5, c=2;
System.out.println("Power : " +Math.pow(b,c));
}
}
22. Java program to compare string.
public class compare
{
public static void main(String [] args)
{
String s1 = "abc";
String s2 = "abc";
System.out.println(s1.compareTo(s2));
String s3 = "Abc";
String s4 = "abc";
System.out.println(s3.compareTo(s4));
String s5 = "abc";
String s6 = "ABC";
System.out.println(s5.compareTo(s6));
}
}