JAVA
JAVA
JAVA
}
}
OUTPUT :-
OUTPUT
02. Write a Java program to check if a given Number is Positive or Negative
or Zero
using if..else statement by getting the input of a number of user choice
during
runtime.
import java.util.Scanner;
public class PositiveNegativeZero {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
System.out.print("Enter the number: ");
}
}
OUTPUT
03. Write a Java program to find the largest among three numbers using
if..else
statement by getting the input of three number of user choice during
run time.
import java.util.Scanner;
public class LargestOfThree {
public static void main(String[] args) {
OUTPUT
04. Write a Java program to check whether a number is even or odd using
if...else
statement by getting the input of a number of user choice during run
time.
import java.util.Scanner;
public class EvenOdd {
}
}
OUTPUT
import java.util.Scanner;
public class MultiplicationTable {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
System.out.print("Enter the MultiplicationTable number: ");
int num = reader.nextInt();
for(int i = 1; i <= 10; i++)
{
System.out.printf("%d * %d = %d \n", num, i, num * i);
}
}
}
OUTPUT
07. Write a Java program to find the Area of Rectangle by getting the
input of
length and breadth from the user during run time.
import java.util.Scanner;
public class AreaOfRectangle {
OUTPUT
08. Write a JAVA program to print the sum of first 10 natural numbers 1
to 10.
int i, sum = 0;
sum = sum + i;
}
09. Write a Java program to print the FIBONACCI SERIES by getting the
input of
number of terms in the series during run time.
0 1 1 2 3 5 8 13 21 34
import java.util.Scanner;
class Fibonacci
{
OUTPUT
10. Write a Java program to print the FACTORIAL of a given number by
getting
import java.util.Scanner;
public class Factorial {
public static void main(String arg[])
{
int n,fact=1;
Scanner s=new Scanner(System.in);
System.out.println("Enter a number:");
n=s.nextInt();
for(int i=1;i<=n;i++)
{
fact=fact*i;
}
System.out.println("Factorial of the given number "+n +" is " +fact);
}
}
OUTPUT
11. Write a program to sort an Array of strings in alphabetical order
import java.io.*;
class GFG {
public static void main(String[] args)
{
int n = 4;
if (names[i].compareTo(names[j]) > 0) {
temp = names[i];
names[i] = names[j];
names[j] = temp;
}
}
}
System.out.println(
"The names in alphabetical order are: ");
for (int i = 0; i < n; i++) {
System.out.println(names[i]);
}
}
}
OUTPUT
14. write a program in java to sort an array in ascending order and display it.
import java.util.Arrays;
public class GFG {
public static void main(String[] args)
{
int[] array = new int[] { 12,45,78,5,33 };
Arrays.sort(array);
System.out.println(Arrays.toString(array));
}
}
OUTPUT
15. Java program to write a code in for loop from 1 to 10
class GFG {
public static void main(String[] args)
{
for (int i = 1; i <= 10; i++) {
System.out.println(i);
}
}
}
OUTPUT