0% found this document useful (0 votes)
7 views8 pages

Java Programs for Basic Control Structures

The document contains several Java programs demonstrating basic programming concepts. It includes a program to print the days of the week using a switch statement, check if an input character is a vowel or consonant using both if-else and switch statements, and determine a student's grade based on marks. Additionally, it shows examples of printing the first 10 numbers using for, while, and do-while loops.

Uploaded by

leelarani
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)
7 views8 pages

Java Programs for Basic Control Structures

The document contains several Java programs demonstrating basic programming concepts. It includes a program to print the days of the week using a switch statement, check if an input character is a vowel or consonant using both if-else and switch statements, and determine a student's grade based on marks. Additionally, it shows examples of printing the first 10 numbers using for, while, and do-while loops.

Uploaded by

leelarani
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

1.

Java Program: Print Days of the Week using switch

[Link] Grade of the student using mark

3. Java program to check whether an input alphabet is a vowel or a consonant using if-else and
switch statements.

[Link] for,while and do while loop print first 10 numbers


import [Link];

public class DaysOfWeek {

public static void main(String[] args) {

Scanner input = new Scanner([Link]);

[Link]("Enter a number (1 to 7): ");

int day = [Link]();

switch(day) {

case 1:

[Link]("Sunday");

break;

case 2:

[Link]("Monday");

break;

case 3:

[Link]("Tuesday");

break;

case 4:

[Link]("Wednesday");

break;

case 5:

[Link]("Thursday");

break;
case 6:

[Link]("Friday");

break;

case 7:

[Link]("Saturday");

break;

default:

[Link]("Invalid input! Please enter a number


between 1 and 7.");

[Link]();

import [Link];

public class VowelOrConsonantSwitch {

public static void main(String[] args) {


Scanner input = new Scanner([Link]);

[Link]("Enter an alphabet: ");

char ch = [Link]().toLowerCase().charAt(0);

if (![Link](ch)) {

[Link]("Not a valid alphabet.");

} else {

switch(ch) {

case 'a':

case 'e':

case 'i':

case 'o':

case 'u':

[Link](ch + " is a vowel.");

break;

default:

[Link](ch + " is a consonant.");

[Link]();

}
import [Link];

public class VowelOrConsonant {

public static void main(String[] args) {

Scanner input = new Scanner([Link]);

[Link]("Enter an alphabet: ");

char ch = [Link]().toLowerCase().charAt(0);

if (![Link](ch)) {

[Link]("Not a valid alphabet.");

} else if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') {

[Link](ch + " is a vowel.");

} else {

[Link](ch + " is a consonant.");

[Link]();

import [Link];

public class GradeCheck {

public static void main(String[] args) {


Scanner input = new Scanner([Link]);

[Link]("Enter your marks (0–100): ");

int marks = [Link]();

if (marks >= 90 && marks <= 100) {

[Link]("Grade: A");

} else if (marks >= 80) {

[Link]("Grade: B");

} else if (marks >= 70) {

[Link]("Grade: C");

} else if (marks >= 60) {

[Link]("Grade: D");

} else if (marks >= 50) {

[Link]("Grade: E");

} else if (marks >= 0) {

[Link]("Grade: F (Fail)");

} else {

[Link]("Invalid marks!");

[Link]();

}
public class ForLoopExample {

public static void main(String[] args) {

[Link]("Using for loop:");

for (int i = 1; i <= 10; i++) {

[Link](i);

public class WhileLoopExample {

public static void main(String[] args) {

[Link]("Using while loop:");

int i = 1;

while (i <= 10) {

[Link](i);

i++;

public class DoWhileLoopExample {

public static void main(String[] args) {

[Link]("Using do-while loop:");

int i = 1;
do {

[Link](i);

i++;

} while (i <= 10);

You might also like