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

TESTClass8compchJAVA-Decisionmakingstatement

The document provides an overview of conditional constructs in Java, specifically focusing on if, if-else, and their syntax. It includes example programs that demonstrate how to use these statements to check conditions such as pass/fail, positive/negative numbers, odd/even numbers, and divisibility by specific integers. Additionally, it offers several programming exercises for students to practice these concepts.

Uploaded by

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

TESTClass8compchJAVA-Decisionmakingstatement

The document provides an overview of conditional constructs in Java, specifically focusing on if, if-else, and their syntax. It includes example programs that demonstrate how to use these statements to check conditions such as pass/fail, positive/negative numbers, odd/even numbers, and divisibility by specific integers. Additionally, it offers several programming exercises for students to practice these concepts.

Uploaded by

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

ST.

MARY’S ENGLISH SCHOOL


CLASS –VIII
SUBJECT – Computer Studies
CH –JAVA DECISION MAKING STATEMENT

Conditional construct or Decision Making statements are specific statements that allow us to check a condition
and execute certain parts of code depending on whether the condition is true or false.
Conditional statements in Java are : if, if-else, if–else if –else and switch case. (if and if-else is in your syllabus)

if statement
Syntax
if (expression) {
// statements
}

// Program to display the result - pass / fail(passing marks - 50 /100)


class ifEg
{
public static void main(String args[])
{
int comp=30;

if(comp>=50)
System.out.println("PASS");

if(comp<50)
System.out.println("FAIL");

}
}

if else

Syntax
if (expression)
{
// statements
}
else
{
// statements
}

Pag e1|4
// Program to display the result - pass / fail(passing marks - 50 /100)
class ifEg
{
public static void main(String args[])
{
int comp=30;

if(comp>=50)
System.out.println("PASS");
else
System.out.println("FAIL");
}
}
WAP to accept a number from the user and check whether it is positive or negative.

class PosNeg
{
public static void main(String args[])
{
Scanner in =new Scanner(System.in);
System.out.println(“Enter any number”);
int n = in.nextInt();

if(n >0 )
{
System.out.println(“Positive number”);
}
else
{
System.out.println(“Negative number”);
}
}
}

WAP to accept a number from the user and check whether it is odd or even.

class OddEven
{
public static void main(String args[])
{
Scanner in =new Scanner(System.in);
System.out.println(“Enter any number”);
int n = in.nextInt();

if(n % 2==0 )
{
System.out.println(“Even number”);
}
else
{
System.out.println(“Odd number”);
}
}
}

Pag e2|4
WAP to accept a number from the user and check whether it is divisible by 5 or not.

class Divisible
{
public static void main(String args[])
{
Scanner in =new Scanner(System.in);
System.out.println(“Enter any number”);
int n = in.nextInt();

if(n % 5==0 )
{
System.out.println(“ number is divisible by 5”);
}
else
{
System.out.println(“number is not divisible by 5”);
}
}
}

WAP to accept a number from the user and check whether it is divisible by 3 and 11 or not.

class Divisible
{
public static void main(String args[])
{
Scanner in =new Scanner(System.in);
System.out.println(“Enter any number”);
int n = in.nextInt();

if(n % 3==0 && n% 11==0 )


{
System.out.println(“ number is divisible both by 3 and 11”);
}
else
{
System.out.println(“number is not divisible by 3 and 11”);
}
}
}

WAP to accept a number from the user ,take out the last digit and check whether it is divisible by 7 or not.

class Divisible
{
public static void main(String args[])
{
Scanner in =new Scanner(System.in);
System.out.println(“Enter any number”);
int n = in.nextInt();
int ld=n%10;
if(ld %7==0 )
{

Pag e3|4
System.out.println(“ last digit is divisible both by 7”);
}
else
{
System.out.println(“last digit is not divisible by 7”);
}
}
}

Pag e4|4

You might also like