Upload files to "OOP/Java/Lab/Week3"
This commit is contained in:
parent
a48eede8ad
commit
ee1a31b5e1
28
OOP/Java/Lab/Week3/Armstrong.java
Normal file
28
OOP/Java/Lab/Week3/Armstrong.java
Normal file
@ -0,0 +1,28 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
class Armstrong{
|
||||
public static void main(String args[]){
|
||||
Scanner sc = new Scanner(System.in);
|
||||
|
||||
int a,b,digit;
|
||||
int digisum=0;
|
||||
|
||||
System.out.println("Enter the number you went to check for Armstrong-ness:");
|
||||
a = sc.nextInt();
|
||||
|
||||
b = a;
|
||||
|
||||
while(b!=0){
|
||||
digit = b%10;
|
||||
digisum += (digit*digit*digit);
|
||||
b /= 10;
|
||||
}
|
||||
|
||||
if(digisum == a){
|
||||
System.out.println("The number is an armstrong number.");
|
||||
}else{
|
||||
System.out.println("The number is not an armstrong number.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
23
OOP/Java/Lab/Week3/ArraySearch.java
Normal file
23
OOP/Java/Lab/Week3/ArraySearch.java
Normal file
@ -0,0 +1,23 @@
|
||||
import java.util.Scanner;
|
||||
public class ArraySearch {
|
||||
public static void main(String args[]){
|
||||
Scanner sc = new Scanner(System.in);
|
||||
int flag=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=0;i<9;i++){
|
||||
if(array[i] == b){
|
||||
System.out.print(" a["+i+"]");
|
||||
flag++;
|
||||
}
|
||||
}
|
||||
if(flag==0){
|
||||
System.out.print("None. The input value does not exist in the array.");
|
||||
}
|
||||
}
|
||||
}
|
11
OOP/Java/Lab/Week3/LadderFor.java
Normal file
11
OOP/Java/Lab/Week3/LadderFor.java
Normal file
@ -0,0 +1,11 @@
|
||||
public class LadderFor {
|
||||
public static void main(String args[]){
|
||||
for(int i = 1; i<=5 ; i++){
|
||||
for (int j = 0; j<i; j++){
|
||||
System.out.print(i+" ");
|
||||
}
|
||||
System.out.println("");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
14
OOP/Java/Lab/Week3/LadderForEach.java
Normal file
14
OOP/Java/Lab/Week3/LadderForEach.java
Normal file
@ -0,0 +1,14 @@
|
||||
public class LadderForEach {
|
||||
public static void main(String args[]){
|
||||
int[] array = {1,2,3,4,5};
|
||||
|
||||
for(int i: array){
|
||||
for (int j = 0; j<i; j++){
|
||||
System.out.print(i+" ");
|
||||
}
|
||||
System.out.println("");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
27
OOP/Java/Lab/Week3/PrimeGen.java
Normal file
27
OOP/Java/Lab/Week3/PrimeGen.java
Normal file
@ -0,0 +1,27 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class PrimeGen {
|
||||
public static void main(String args[]){
|
||||
Scanner sc = new Scanner(System.in);
|
||||
|
||||
System.out.println("Enter the numbers you want as the lower and upper limits of the prime number generator: ");
|
||||
int n = sc.nextInt();
|
||||
int m = sc.nextInt();
|
||||
|
||||
System.out.println("The Prime Numbers between " + n + " & " + m + " are:");
|
||||
|
||||
for(int i = n; i<=m; i++){
|
||||
int flag = 0;
|
||||
for(int j = 2; j<i; j++){
|
||||
if((i%j)==0){
|
||||
flag++;
|
||||
}
|
||||
}
|
||||
|
||||
if(flag == 0){
|
||||
System.out.print(i+" ");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user