Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assignment1-sharuf baig #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 161 additions & 0 deletions java assignment-sharuf.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
1.the nearest prime number thing:-

package com.company;

import java.util.Scanner;

public class Main {

public static void main(String[] args) {
System.out.println("enter the whole number ");
Scanner scan=new Scanner(System.in);
int number=scan.nextInt();
int result=0;
while(result!=1)
{
int count=0;
number++;
for(int i=1;i<=number;i++)
{
if(number%i==0)
{
count++;
}
}
if(count==2)
{
result=1;
}
}
System.out.println("The nearest prime number is"+number);

}
}
2.fibonacci series thing :-

package com.company;

import java.util.Scanner;

public class Main {

public static void main(String[] args) {
System.out.println("enter the length of the fibonacci series");
Scanner scan = new Scanner(System.in);
int len = scan.nextInt();
Main pro = new Main();
System.out.println("The series upto length "+len+" is as follows");
for (int i = 1; i <= len; i++) {
System.out.println(pro.fibonacci(i));
}
}

int fibonacci(int n) {
if (n == 1)
return 0;
else if (n == 2)
return 1;
else
return fibonacci(n - 1) + fibonacci(n - 2);
}
}
3.median thing :-

package com.company;

import java.util.Scanner;
import java.util.Arrays;

public class Main {

public static void main(String[] args) {
Scanner scan =new Scanner(System.in);
System.out.println("enter the number of numbers you want to enter");
int len=scan.nextInt();
System.out.println("enter the numbers to find the median");
float[] a=new float[len];
for(int i=0;i<len;i++)
{
a[i]=scan.nextFloat();
}

Arrays.sort(a);
System.out.println("the sorted array is"+Arrays.toString(a));
if(len%2!=0)
{
System.out.println("the median is"+a[(len+1)/2 -1]);
}
else
{
System.out.println("the median is"+(a[len/2 -1]+a[len/2 ])/2);
}



}

}
4. box thing :-

package com.company;

import java.util.Scanner;
import java.util.Arrays;

public class Main {

public static void main(String[] args) {
Box box1 = new Box();
Box box2 = new Box(5, 2, 4, "yellow");
Box box3 = new Box(box2);
Main v=new Main();
System.out.println("the volume of first box is "+v.volume(box1.length,box1.height,box1.width));
System.out.println("the volume of second box is "+v.volume(box2.length,box2.height,box2.width));
System.out.println("the volume of copy box3 is "+v.volume(box3.length,box3.height,box3.width));
System.out.println("count : "+Box.count);


}
float volume(float l,float h,float w)
{
return l*w*h;

}
}
class Box {
float length,height,width;
String color;
static int count;
Box( )
{
System.out.println("constructor ");
length=1;
width=1;
height=1;
color="red";
count++;
}
Box(float length,float width,float height,String color)
{
System.out.println("constructor with arguments");
this.length=length;
this.width=width;
this.height=height;
this.color=color;
count++;
}
Box(Box obj)
{
System.out.println("in copy constructor");
length=obj.length;
width=obj.width;
height=obj.height;
color=obj.color;
count++;
}

}