0% found this document useful (0 votes)
14 views4 pages

Basic Programs Java

The document contains multiple Java programs that perform different tasks. These include checking if a character is a vowel or consonant, determining if an integer is positive, negative, or zero, verifying if a character is an alphabet, checking if a number is odd or even, and calculating the area of a circle based on a given radius. Each program uses the Scanner class for user input and contains simple conditional statements to produce the desired output.
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)
14 views4 pages

Basic Programs Java

The document contains multiple Java programs that perform different tasks. These include checking if a character is a vowel or consonant, determining if an integer is positive, negative, or zero, verifying if a character is an alphabet, checking if a number is odd or even, and calculating the area of a circle based on a given radius. Each program uses the Scanner class for user input and contains simple conditional statements to produce the desired output.
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

Print element is vowel or consonant

import [Link];

class Main{

public static void main(String[]args){

Scanner sc=new Scanner([Link]);

[Link]("Enter element:");

char n=[Link]().charAt(0);

if(n=='a'|| n=='e'||n=='i'|| n=='o'||n=='u'||n=='A'|| n=='E'||n=='I'|| n=='O'|| n=='U'){

[Link]("Element is a vowel");

else{

[Link]("Element is a consonant");

Positive / negative integer:

import [Link];

class Main{

public static void main(String[]args){

Scanner sc=new Scanner([Link]);

[Link]("Enter element:");

int n=[Link]();

if(n>0){

[Link]("Element is positive integer");

else if(n<0){

[Link]("Element is negative integer");

}
else{

[Link]("Element is zero");

Alphabet or not

import [Link];

class Main{

public static void main(String[]args){

Scanner sc=new Scanner([Link]);

[Link]("Enter element:");

char n=[Link]().charAt(0);

if((n>='A'&& n<='Z')||(n>='a'&& n<='z')){

[Link]("Element is alphabet");

else{

[Link]("Element is not alphabet");

Built in method:

import [Link];

class Main{

public static void main(String[]args){

Scanner sc=new Scanner([Link]);

[Link]("Enter element:");
char n=[Link]().charAt(0);

if([Link](n)){

[Link]("Element is alphabet");

else{

[Link]("Element is not alphabet");

Odd or Even:

import [Link];

class Main{

public static void main(String[]args){

Scanner sc=new Scanner([Link]);

[Link]("Enter number:");

int n=[Link]();

if(n%2==0){

[Link]("Even number");

else{

[Link]("Odd number");

Area of circle:

import [Link];
class Main{

public static void main(String[]args){

Scanner sc=new Scanner([Link]);

[Link]("Enter radius:");

int r=[Link]();

double area=3.14*r*r;

[Link]("Area is:"+area);

You might also like