Java Program
Java Program
Java Program
import java.util.Scanner;
import java.lang.Math;
temp=n;
while(temp>0)
temp = temp/10;
digits++;
temp = n;
while(temp>0)
temp = temp/10;
if(n==sum)
return true;
int num;
if(isArmstrong(i))
Output:
int n = sc.nextInt();
double t;
double sqrtroot=num/2;
do
t=sqrtroot;
sqrtroot=(t+(num/t))/2;
while((t-sqrtroot)!= 0);
return sqrtroot;
Output 1:
Enter a number: 12
int i,m=0,flag=0;
int n=3;
m=n/2;
if(n==0||n==1){
}else{
for(i=2;i<=m;i++){
if(n%i==0){
flag=1;
break;
}
Output:
3 is prime number
34. Write a java program to print all prime numbers between two numbers.
if(low % i == 0) {
flag = true;
break;
++low;
Output
23 29 31 37 41 43 47
35. Write a java program to print array elements using array class methods.
System.out.println(element);
Output
int j = n;
b[j - 1] = a[i];
j = j - 1;
reverse(arr, arr.length);
Output
50
40
30
20
10
+ array.length);
Output:
arr2[i] = arr1[i];
System.out.println();
Output:
12345
12345
class Test {
{
int sum = 0;
int i;
sum += arr[i];
return sum;
+ sum());
Output
for(int i=0;i<arr.length;i++){
if(arr[i] == key){
return i;
return -1;
}
}
Output:
50 is found at index: 3
int temp = 0;
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
System.out.println();
Output:
Elements of original array:
52871
12578
int temp = 0;
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
System.out.println();
}
}
Output:
52871
87521
max = arr[i];
Output:
min = arr[i];
Output:
import java.util.ArrayList;
import java.util.Arrays;
System.out.println("Array:"+Arrays.toString(arr));
arrayList.add(7);
arr = arrayList.toArray(arr);
Output:
Array:[1, 2, 3, 4, 5, 6]
import java.util.Arrays;
class GFG {
public static int[] removeTheElement(int[] arr, int index)
return arr;
if (i == index) {
continue;
anotherArray[k++] = arr[i];
return anotherArray;
int[] arr = { 1, 2, 3, 4, 5 };
+ Arrays.toString(arr));
int index = 2;
+ Arrays.toString(arr));
Output
class Main {
firstTerm = secondTerm;
secondTerm = nextTerm;
Output
}
}
System.out.println();
Output
-2 8 7
10 8 6
int a[][] = {
{4, 5, 6},
{3, 4, 1},
{1, 2, 3}
};
int b[][] = {
{2, 0, 3},
{2, 3, 1},
{1, 1, 1}
};
rows = a.length;
cols = a[0].length;
System.out.println();
Output:
1 5 3
1 1 0
0 1 2
int a[][]={{1,1,1},{2,2,2},{3,3,3}};
int b[][]={{1,1,1},{2,2,2},{3,3,3}};
for(int j=0;j<3;j++){
c[i][j]=0;
for(int k=0;k<3;k++)
c[i][j]+=a[i][k]*b[k][j];
}//end of k loop
System.out.print(c[i][j]+" ");
}System.out.println();//new line
}}
Output:
666
12 12 12
18 18 18
display(matrix);
transpose[j][i] = matrix[i][j];
display(transpose);
}
public static void display(int[][] matrix) {
System.out.println();
Output
2 3 4
5 6 4
2 5
3 6
4 4
if (n == 1)
return 1;
else
return(n * factorial(n-1));
}
}
Output:
if(style == style2)
System.out.println("Equal");
else
System.out.println("Not Equal");
Output
Equal
import java.io.*;
import java.util.Scanner;
class GFG {
char ch;
System.out.println("Geeks");
{
ch= str.charAt(i);
nstr= ch+nstr; }
Output