You are on page 1of 4

Write a Program to enter student details and print it(Console IO).

import java.util.Scanner;
class ConsoleIO
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);

int sid;
String name;
String course;
double fee;

System.out.println("Enter Student ID:");


sid=sc.nextInt();
System.out.println("Enter Name:");
name=sc.next();
System.out.println("Enter Course:");
course=sc.next();
System.out.println("Enter Fee:");
fee=sc.nextDouble();

System.out.println("Student ID:"+sid);
System.out.println("Student Name:"+name);
System.out.println("Course:"+course);
System.out.println("Fee:"+fee);
}
}

Simple IF
class SimpleIf
{
public static void main(String argr[])
{
int a=15;
int b=6;

if(a>b)
{
System.out.println("A is Greater!");
}
else
{
System.out.println("B is Greater!");
}
}
}
Nesting IF
class NestingIf
{
public static void main(String argr[])
{
String g="F";
int per=80;
if(g=="F")
{
if(per>=80)
{
System.out.println("You are Selected!");
}
else
{
System.out.println("You are Not Selected!");
}
}
else
{
System.out.println("Not Applicatble for You! Try Again!");
}
}
}

If..Else..If

class MaxNumber
{
public static void main(String args[])
{
int a=5;
int b=8;
int c=13;

if(a>b && a>c)


{
System.out.println("A is Greater!");
}
if(b>a && b>c)
{
System.out.println("B is Greater!");
}
else
{
System.out.println("C is Greater!");
}
}
}

Switch Statement
class DayName
{
public static void main(String args[])
{
int day=3;
switch(day)
{
case 1:
System.out.println("SUN");
break;
case 2:
System.out.println("MON");
break;
case 3:
System.out.println("TUE");
break;
case 4:
System.out.println("WED");
break;
case 5:
System.out.println("THR");
break;
case 6:
System.out.println("FRI");
break;
case 7:
System.out.println("SAT");
break;
default:
System.out.println("Invalid Day Number");
}

}
}

1. Write a Program enter any number and check number is Odd or Even.
2. Write a Program enter any character and check character is Vowel or Consonant
3. Write a Program enter year number and check year is leap or not.
4. Write a Program enter year and month number and find out how many days in the month.
Interaction Statements
(LOOPS)

While Loop

class WileLoop
{
public static void main(String args[])
{
int c=1;
while(c<=100)
{
System.out.println(c);
c++;
}
}
}

Do While Loop
class DoWhileLoop
{
public static void main(String args[])
{
int c=1;
do
{
System.out.println(c);
c++;
}while(c<=100);
}
}

For Loop
class ForLoop
{
public static void main(String args[])
{

for(int i=1;i<=100;i++)
{
System.out.println(i);
}
}
}

You might also like