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; b = a;
while(b!=0){
c++;
b/=10;
}
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

@ -11,6 +11,7 @@ public class ArraySearch {
System.out.println("The value is found at the locations: "); System.out.println("The value is found at the locations: ");
for(int i:array){ for(int i:array){
if(i == b){ if(i == b){
System.out.print(" a["+index+"]"); System.out.print(" a["+index+"]");

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+" ");
}
}
}
}
}
}
}