Upload files to "OOP/Java/Lab/Week1"
This commit is contained in:
parent
24683dac5a
commit
8542582101
17
OOP/Java/Lab/Week1/Factorial.java
Normal file
17
OOP/Java/Lab/Week1/Factorial.java
Normal file
@ -0,0 +1,17 @@
|
||||
class Factorial
|
||||
{
|
||||
public static void main(String args[])
|
||||
{
|
||||
int a,i,product=1;
|
||||
|
||||
a = Integer.parseInt(args[0]);
|
||||
|
||||
for(i=a;i>0;i--)
|
||||
{
|
||||
product = product * i;
|
||||
}
|
||||
|
||||
System.out.println("Factorial For the Number "+a+" is "+product+".");
|
||||
|
||||
}
|
||||
}
|
16
OOP/Java/Lab/Week1/MultiplicationTable.java
Normal file
16
OOP/Java/Lab/Week1/MultiplicationTable.java
Normal file
@ -0,0 +1,16 @@
|
||||
class MultiplicationTable
|
||||
{
|
||||
public static void main(String args[])
|
||||
{
|
||||
int a,b,i,c;
|
||||
a = Integer.parseInt(args[0]);
|
||||
b = Integer.parseInt(args[1]);
|
||||
|
||||
|
||||
for(i=1;i<=b;i++)
|
||||
{
|
||||
c = a*i;
|
||||
System.out.println(+a+" x "+i+" = "+c);
|
||||
}
|
||||
}
|
||||
}
|
31
OOP/Java/Lab/Week1/NumberClassify.java
Normal file
31
OOP/Java/Lab/Week1/NumberClassify.java
Normal file
@ -0,0 +1,31 @@
|
||||
import java.util.Scanner; // Import the Scanner class
|
||||
|
||||
class NumberClassify {
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
int i,pos=0,zero=0,neg=0;
|
||||
int[] arr;
|
||||
arr = new int[10];
|
||||
|
||||
System.out.println("Enter 10 Numbers:");
|
||||
|
||||
for(i=0;i<10;i++){
|
||||
arr[i] = sc.nextInt();
|
||||
}
|
||||
|
||||
for(i=0;i<10;i++){
|
||||
if(arr[i] > 0){
|
||||
pos++;
|
||||
}else if(arr[i] < 0){
|
||||
neg++;
|
||||
}else{
|
||||
zero++;
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("There are "+pos+" positive numbers.");
|
||||
System.out.println("There are "+neg+" negative numbers.");
|
||||
System.out.println("There are "+zero+" zero values.");
|
||||
|
||||
}
|
||||
}
|
24
OOP/Java/Lab/Week1/Palindrome.java
Normal file
24
OOP/Java/Lab/Week1/Palindrome.java
Normal file
@ -0,0 +1,24 @@
|
||||
class Palindrome
|
||||
{
|
||||
public static void main(String args[])
|
||||
{
|
||||
int a,i,c,temp,rev;
|
||||
a = Integer.parseInt(args[0]);
|
||||
|
||||
temp = a;
|
||||
rev = 0;
|
||||
|
||||
while(temp!=0)
|
||||
{
|
||||
c = temp%10;
|
||||
rev = rev*10 + c;
|
||||
temp = temp/10;
|
||||
}
|
||||
|
||||
if(rev == a){
|
||||
System.out.println("The number is a palindrome.");
|
||||
}else{
|
||||
System.out.println("The number is not a palindrome.");
|
||||
}
|
||||
}
|
||||
}
|
13
OOP/Java/Lab/Week1/Rectangle.java
Normal file
13
OOP/Java/Lab/Week1/Rectangle.java
Normal file
@ -0,0 +1,13 @@
|
||||
class Rectangle
|
||||
{
|
||||
public static void main(String args[])
|
||||
{
|
||||
int a,b,c,l;
|
||||
l = Integer.parseInt(args[0]);
|
||||
b = Integer.parseInt(args[1]);
|
||||
c = 2*(l+b);
|
||||
a = l*b;
|
||||
System.out.println("The Circumference of the Rectangle = "+ c);
|
||||
System.out.println("The Area of the Rectangle = "+ a);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user