0% found this document useful (0 votes)
1 views5 pages

Control Structures

Uploaded by

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

Control Structures

Uploaded by

amarerhnjohn
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

ERHN JOHN AMAR

BSIT

BT102

Source code

Positive And Negative:

import [Link];

public class PositiveNegative {

public static void main(String[] args) {

Scanner input = new Scanner([Link]);

[Link]("Enter a number: ");

double num = [Link]();

if (num > 0) {

[Link](num + " is positive.");

} else if (num < 0) {

[Link](num + " is negative.");

} else {

[Link]("The number is zero.");

[Link]();

}
SOURCE CODE

Month Name:

import [Link];

public class MonthName {

public static void main(String[] args) {

Scanner input = new Scanner([Link]);

[Link]("Enter any number (1-12): ");

int monthNum = [Link]();

String monthName = "";

switch (monthNum) {

case 1: monthName = "January"; break;

case 2: monthName = "February"; break;

case 3: monthName = "March"; break;

case 4: monthName = "April"; break;

case 5: monthName = "May"; break;


case 6: monthName = "June"; break;

case 7: monthName = "July"; break;

case 8: monthName = "August"; break;

case 9: monthName = "September"; break;

case 10: monthName = "October"; break;

case 11: monthName = "November"; break;

case 12: monthName = "December"; break;

default: monthName = "Invalid number! Please enter 1–12.";

[Link]("Month name: " + monthName);

[Link]();

}
Source code

Product and average:

Import [Link];

Public class ProductAndAverage {

Public static void main(String[] args) {

Scanner input = new Scanner([Link]);

Double product = 1;

Double sum = 0;

[Link](“Enter 5 numbers:”);

For (int I = 1; I <= 5; i++) {

[Link](“Number “ + I + “: “);

Double num = [Link]();

Product *= num;

Sum += num;

Double average = sum / 5;

[Link](“Product of numbers: “ + product);

[Link](“Average of numbers: “ + average);

[Link]();

}
}

You might also like