Upload files to "OOP/Java/Lab/Week3"

This commit is contained in:
Aadit Agrawal 2024-08-10 11:20:04 +05:30
parent d7432df050
commit 490ff117eb
3 changed files with 74 additions and 27 deletions

View File

@ -1,4 +1,5 @@
import java.util.Scanner; import java.util.Scanner;
import java.lang.Math;
class Armstrong{ class Armstrong{
public static void main(String args[]){ public static void main(String args[]){
@ -6,15 +7,23 @@ class Armstrong{
int a,b,digit; int a,b,digit;
int digisum=0; int digisum=0;
int c=0;
System.out.println("Enter the number you went to check for Armstrong-ness:"); System.out.println("Enter the number you went to check for Armstrong-ness:");
a = sc.nextInt(); a = sc.nextInt();
b = a;
while(b!=0){
c++;
b/=10;
}
b = a; b = a;
while(b!=0){ while(b!=0){
digit = b%10; digit = b%10;
digisum += (digit*digit*digit); digisum += Math.pow(digit, c);
b /= 10; b /= 10;
} }

View File

@ -1,26 +1,27 @@
import java.util.Scanner; import java.util.Scanner;
public class ArraySearch { public class ArraySearch {
public static void main(String args[]){ public static void main(String args[]){
Scanner sc = new Scanner(System.in); Scanner sc = new Scanner(System.in);
int flag=0,index=0; int flag=0,index=0;
int[] array = {1,2,3,1,5,6,1,8,9}; int[] array = {1,2,3,1,5,6,1,8,9};
System.out.println("Enter the search value:"); System.out.println("Enter the search value:");
int b = sc.nextInt(); int b = sc.nextInt();
System.out.println("The value is found at the locations: "); System.out.println("The value is found at the locations: ");
for(int i:array){
if(i == b){ for(int i:array){
System.out.print(" a["+index+"]"); if(i == b){
flag++; System.out.print(" a["+index+"]");
} flag++;
index++; }
} index++;
}
if(flag==0){
System.out.print("None. The input value does not exist in the array."); if(flag==0){
} System.out.print("None. The input value does not exist in the array.");
} }
} }
}

View File

@ -0,0 +1,37 @@
public class FourNumberGen {
public static void main(String args[]){
int i,j,k,l;
System.out.println("With Repetition: ");
for(i = 0; i<=9; i++){
for(j = 0; j<=9; j++){
for(k = 0; k<=9; k++){
for(l = 0; l<=9; l++)
{
System.out.print(i+""+j+""+k+""+l+" ");
}
}
}
}
for(i=0;i<10;i++){
System.out.println(" ");
}
System.out.println("Without Repetition: ");
for(i = 0; i<=9; i++){
for(j = 0; j<=9; j++){
for(k = 0; k<=9; k++){
for(l = 0; l<=9; l++)
{
if((i!=j)&(i!=k)&(i!=l)&(j!=k)&(j!=l)&(k!=l)){
System.out.print(i+""+j+""+k+""+l+" ");
}
}
}
}
}
}
}