0% found this document useful (0 votes)
4 views

Assignment 3 Java 57

The document contains a series of Java programming assignments by Shreeya Joshi, including code snippets for various tasks such as checking if a number is even or odd, printing numbers in a loop, checking for leap years, and generating Fibonacci sequences. Each question is presented with its corresponding Java code implementation. The assignments demonstrate basic programming concepts and control structures in Java.

Uploaded by

anishwarushe0725
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Assignment 3 Java 57

The document contains a series of Java programming assignments by Shreeya Joshi, including code snippets for various tasks such as checking if a number is even or odd, printing numbers in a loop, checking for leap years, and generating Fibonacci sequences. Each question is presented with its corresponding Java code implementation. The assignments demonstrate basic programming concepts and control structures in Java.

Uploaded by

anishwarushe0725
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

ASSIGNMENT NO.

OBJECT ORIENTED PROGRAMMING


NAME-SHREEYA JOSHI
ROLLNO.-57
PRN-2122000723

Q1)
import java .util.Scanner ;
public class Main {
public static void main(String[] ignoredArgs){
int number;
Scanner sc=new Scanner(System.in);
System.out.println("enter your number");
number= sc.nextInt();
if (number%2==0){
System.out.println("given number is even");
}else {
System.out.println("given number is odd");
}

}
Q2)
public class Main {
public static void main(String[] ignoredArgs){
int i=1;
do{
System.out.println(i);
i++;
}while(i<=10);

}
}

Q3)

class Main {
public static void main(String[] args) {
int i = 3, n = 8;
while(i <= n) {
System.out.println(i);
i++;
}
}
}

Q4)

class Main {
public static void main(String[] args) {

int i = 2, n = 9;

while(i <= n) {
System.out.println(i);
i++;
}
}
}

Q6)
statement will execute 12 times
Q7)
public class main
{
public static void main (int n)
{
int i, j;
for(i=0; i<n; i++) //outer loop for number of rows(n) { for(j=2*(n-i);
j>=0; j--)
{
System.out.print(" ");
}
for(j=0; j<=i; j++)
{
System.out.print("* ");
}
System.out.println();
}
}
public static void main(String args[])
{
int n = 4;
rightTriangle(n);
}
}

Q8)
import java.util.Scanner;
public class Check_Leap_Year
{
public static void main(String args[])
{
Scanner s = new Scanner(System.in);
System.out.print("Enter any year:");
int year = s.nextInt();
boolean flag = false;
if(year % 400 == 0)
{
flag = true;
}
else if (year % 100 == 0)
{
flag = false;
}
else if(year % 4 == 0)
{
flag = true;
}
else
{
flag = false;
}
if(flag)
{
System.out.println("Year "+year+" is a Leap Year");
}
else
{
System.out.println("Year "+year+" is not a Leap Year");
}
}
}

Q9)
class FibonacciExample1{
public static void main(String args[])
{
int n1=0,n2=1,n3,i,count=10;
System.out.print(n1+" "+n2);//printing 0 and 1

for(i=2;i<count;++i)//loop starts from 2 because 0 and 1 are already printed


{
n3=n1+n2;
System.out.print(" "+n3);
n1=n2;
n2=n3;
}

}}

Q5)public class display{


public static void main (string[]args){
for (int i=1;i<5;i++){
system.out.println(i+" "+(6-i));
}
}

You might also like