Found 2617 Articles for Java

Java Program for array rotation

AmitDiwan
Updated on 10-Aug-2023 12:12:06

312 Views

An array is a linear data structure that is used to store a group of elements with similar datatypes. It stores data in a sequential manner. Once we create an array we can't change its size i.e. it can store a fixed number of elements. The array comes with a vast application and use case. Also, we can perform numerous operations on arrays. This article will help you to understand the basics of arrays and also, we will make java programs to perform right and left rotation operations on arrays. Java Program for Array Rotation First, let's understand the term ... Read More

Java Program to print Number series without using any loop

AmitDiwan
Updated on 07-Jul-2020 07:45:33

1K+ Views

Following is the Java code to print Number srries without using any loop −Example Live Demopublic class Demo{    public static void main(String[] args){       int my_num = 0;       System.out.println("The numbers without using loop have been printed below");       print_without_loop(my_num);    }    public static void print_without_loop(int my_num){       if(my_num

Java Program for Largest K digit number divisible by X

AmitDiwan
Updated on 07-Jul-2020 07:42:12

138 Views

Following is the Java program for largest K digit number divisible by X −Example Live Demoimport java.io.*; import java.lang.*; public class Demo{    public static int largest_k(int val_1, int val_2){       int i = 10;       int MAX = (int)Math.pow(i, val_2) - 1;       return (MAX - (MAX % val_1));    }    public static void main(String[] args){       int val_1 = 25;       int val_2 = 2;       System.out.println("The largest 2 digit number divisible by 25 is ");       System.out.println((int)largest_k(val_1, val_2));    } }OutputThe largest 2 ... Read More

Java Program for Longest Increasing Subsequence

AmitDiwan
Updated on 07-Jul-2020 07:38:35

2K+ Views

Following is the Java program for longest increasing subsequence −Example Live Demopublic class Demo{    static int incre_subseq(int my_arr[], int arr_len){       int seq_arr[] = new int[arr_len];       int i, j, max = 0;       for (i = 0; i < arr_len; i++)          seq_arr[i] = 1;       for (i = 1; i < arr_len; i++)       for (j = 0; j < i; j++)       if (my_arr[i] > my_arr[j] && seq_arr[i] < seq_arr[j] + 1)       seq_arr[i] = seq_arr[j] + 1;     ... Read More

Java Program for Longest Common Subsequence

AmitDiwan
Updated on 04-Jul-2020 10:55:09

260 Views

Following is the Java program for Longest Common Subsequence −Example Live Demopublic class Demo{    int subseq(char[] a, char[] b, int a_len, int b_len){       int my_arr[][] = new int[a_len + 1][b_len + 1];       for (int i = 0; i

Printing Triangle Pattern in Java

AmitDiwan
Updated on 04-Jul-2020 10:51:38

1K+ Views

Following is the Java program to print Triangle pattern −Example Live Demoimport java.util.*; public class Demo{    public static void main(String[] args){       Scanner my_scan = new Scanner(System.in);       System.out.println("Enter the number of rows which needs to be printed");       int my_row = my_scan.nextInt();       for (int i = 1; i = i; j--){             System.out.print(" ");          }          for (int j = 1; j

Printing Integer between Strings in Java

AmitDiwan
Updated on 04-Jul-2020 10:49:27

898 Views

Following is the Java program to print integer between Strings −Example Live Demopublic class Demo{    public static void main(String[] args){       System.out.println("The equals symbol is present between two integer values ");       System.out.println(45+5 + "=" +(56+11));       System.out.println(45+5 + " equals symbol " +(56+11));    } }OutputThe equals symbol is present between two integer values 50=67 50 equals symbol 67A class named Demo contains the main function that prints integer values between two strings.

Rename multiple files using Java

AmitDiwan
Updated on 04-Jul-2020 10:46:58

973 Views

Following is the code to rename multiple files using Java −Exampleimport java.io.File; import java.io.IOException; public class Demo{    public static void main(String[] argv) throws IOException{       String path_to_folder = "path\to\folder\where\multiple\files\are\present";       File my_folder = new File(path_to_folder);       File[] array_file = my_folder.listFiles();       for (int i = 0; i < array_file.length; i++){          if (array_file[i].isFile()){             File my_file = new File(path_to_folder + "\" + array_file[i].getName());             String long_file_name = array_file[i].getName();             String[] my_token = long_file_name.split("\s"); ... Read More

How to clear screen using Java?

AmitDiwan
Updated on 04-Jul-2020 10:44:46

3K+ Views

Following is the code to clear screen using Java −Example Live Demopublic class Demo{    public static void main(String[] args){       System.out.print("\033[H\033[2J");       System.out.flush();    } }OutputThe screen would be clearedA class named Demo contains the main function. Here, the ANSI escape code is written, that clears the screen. The flush function resets the cursor to the top of the window screen.

Java Program for check if a given number is Fibonacci number?

AmitDiwan
Updated on 04-Jul-2020 10:43:07

1K+ Views

Following is the Java program to check if a given number is Fibonacci −Example Live Demopublic class Demo{    static boolean perfect_square_check(int val){       int s = (int) Math.sqrt(val);       return (s*s == val);    }    static boolean fibonacci_num_check(int n){       return perfect_square_check(5*n*n + 4) || perfect_square_check(5*n*n - 4);    }    public static void main(String[] args){       for (int i = 6; i

Advertisements