From 490ff117ebfcd3619b576e08847df3bac363578c Mon Sep 17 00:00:00 2001 From: Aadit Agrawal Date: Sat, 10 Aug 2024 11:20:04 +0530 Subject: [PATCH] Upload files to "OOP/Java/Lab/Week3" --- OOP/Java/Lab/Week3/Armstrong.java | 11 +++++- OOP/Java/Lab/Week3/ArraySearch.java | 53 ++++++++++++++------------- OOP/Java/Lab/Week3/FourNumberGen.java | 37 +++++++++++++++++++ 3 files changed, 74 insertions(+), 27 deletions(-) create mode 100644 OOP/Java/Lab/Week3/FourNumberGen.java diff --git a/OOP/Java/Lab/Week3/Armstrong.java b/OOP/Java/Lab/Week3/Armstrong.java index 0354ca9..9f49448 100644 --- a/OOP/Java/Lab/Week3/Armstrong.java +++ b/OOP/Java/Lab/Week3/Armstrong.java @@ -1,4 +1,5 @@ import java.util.Scanner; +import java.lang.Math; class Armstrong{ public static void main(String args[]){ @@ -6,15 +7,23 @@ class Armstrong{ int a,b,digit; int digisum=0; + int c=0; System.out.println("Enter the number you went to check for Armstrong-ness:"); a = sc.nextInt(); + + b = a; + + while(b!=0){ + c++; + b/=10; + } b = a; while(b!=0){ digit = b%10; - digisum += (digit*digit*digit); + digisum += Math.pow(digit, c); b /= 10; } diff --git a/OOP/Java/Lab/Week3/ArraySearch.java b/OOP/Java/Lab/Week3/ArraySearch.java index 1d2f9c3..b2d2ba0 100644 --- a/OOP/Java/Lab/Week3/ArraySearch.java +++ b/OOP/Java/Lab/Week3/ArraySearch.java @@ -1,26 +1,27 @@ -import java.util.Scanner; -public class ArraySearch { - public static void main(String args[]){ - Scanner sc = new Scanner(System.in); - int flag=0,index=0; - - int[] array = {1,2,3,1,5,6,1,8,9}; - - System.out.println("Enter the search value:"); - int b = sc.nextInt(); - - System.out.println("The value is found at the locations: "); - - for(int i:array){ - if(i == b){ - System.out.print(" a["+index+"]"); - flag++; - } - index++; - } - - if(flag==0){ - System.out.print("None. The input value does not exist in the array."); - } - } -} +import java.util.Scanner; +public class ArraySearch { + public static void main(String args[]){ + Scanner sc = new Scanner(System.in); + int flag=0,index=0; + + int[] array = {1,2,3,1,5,6,1,8,9}; + + System.out.println("Enter the search value:"); + int b = sc.nextInt(); + + System.out.println("The value is found at the locations: "); + + + for(int i:array){ + if(i == b){ + System.out.print(" a["+index+"]"); + flag++; + } + index++; + } + + if(flag==0){ + System.out.print("None. The input value does not exist in the array."); + } + } +} diff --git a/OOP/Java/Lab/Week3/FourNumberGen.java b/OOP/Java/Lab/Week3/FourNumberGen.java new file mode 100644 index 0000000..58b196d --- /dev/null +++ b/OOP/Java/Lab/Week3/FourNumberGen.java @@ -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+" "); + } + } + } + } + } + + + } +}