You are on page 1of 6

JAVA LAB-2

1)

package com.company;
import java.util.Scanner;

public class Main {

public static void main(String[] args) {


// write your code here
Scanner input = new Scanner(System.in);
int m, days;
int op=1;
while(op>0)
{
System.out.println("Enter Month(1-12)");
System.out.println("1-JAN 2-FEB 3-MAR 4-APR 5-MAY 6-JUN 7- JUL 8-AUG 9-SEP 10-OCT 11-
NOV 12-DEC");
m = input.nextInt();

if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12)
days = 31;
else if (m == 2)
days = 28;
else
days = 30;

System.out.println("The entered Month has " + days + " days");

System.out.println("Enter 1 to Continue / 0 to EXIT :");


op = input.nextInt();
}
}

2)

package com.company;
import java.util.Scanner;
public class Main {

public static void main(String[] args) {


Scanner input = new Scanner(System.in);
String chr;
char ch;
int op = 1, s;
while (op > 0) {
System.out.println("Enter A character :");
chr = input.next();
ch = chr.charAt(0);
s = chr.length();
if (s > 1 || Character.isLetter(ch) == false)
System.out.println("Error : ");
else {
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'A' || ch == 'E' || ch == 'I'
|| ch == 'O' || ch == 'U')
System.out.println("The character is a Vowel");
else
System.out.println("Entered Character is a Consonant:");
}
System.out.println("TO continue press 1, To exit press 0");
op = input.nextInt();
}
}
}

3)

package com.company;
import java.util.Scanner;
public class Main {

public static void main(String[] args) {


// write your code here
Scanner input = new Scanner(System.in);

int n, sum = 0, val;

System.out.println("Enter A Number :");


n = input.nextInt();

while (n != 0) {
val = n % 10;
sum = sum + val;
n = n / 10;
}
System.out.println("the Sum of Digits is " + sum);

}
}

4)

package com.company;
import java.util.Scanner;
public class Main {

public static void main(String[] args) {


Scanner input = new Scanner(System.in);

int dist, sum = 0, hour, min, sec;


float speed, time;

System.out.println("Enter The Distance :");


dist = input.nextInt();

System.out.println("Enter The Time (Hours) :");


hour = input.nextInt();

System.out.println(" The Time (Min) :");


min = input.nextInt();

System.out.println(" The Time (Seconds) :");


sec = input.nextInt();

time = (hour * 3600) + (min * 60) + sec;


speed = dist / time;

System.out.println(" The Speed in (m/s) :" + speed);

speed = speed * 18F / 5F;


System.out.println(" The Speed in (km/hr) :" + speed);

speed = speed / 1.609F;

System.out.println(" The Speed in (miles/hr) :" + speed);

}
}

5)

package com.company;
import java.util.Scanner;

public class Main {

public static void main(String[] args) {


// write your code here
Scanner input = new Scanner(System.in);
int num1, num2, num3;
float speed, time;
int op = 1;
while (op > 0) {
System.out.println("Enter The Three Numbers :");
num1 = input.nextInt();
num2 = input.nextInt();
num3 = input.nextInt();

if (num1 < num2 && num2 < num3)


System.out.println(" The Three Numbers Are INCREASING ");
else if (num1 > num2 && num2 > num3)
System.out.println(" The Three Numbers Are Decreasing ");
else
System.out.println(" The Three Numbers Are neither Increasing or Decreasing order");
System.out.println("Enter 1 to Continue / 0 to EXIT :");
op = input.nextInt();
}
}
}

You might also like