Ad

Some programes first day (mini projact in java)

import java.util.*;

public class Task
{

public static void main(String args[])
{

System.out.println("====Mainmanu====");
System.out.println("1: Table of 5");
System.out.println("2: Even and odd from 1 to 10");
System.out.println("3: Using all data types");
System.out.println("4: Grade printing system");
System.out.println("5: Sum of 10 numbers");
System.out.println("6: Factorial given point");
System.out.println("7: print reserve number");

System.out.println("Enter the option give statement:");
Scanner option = new Scanner(System.in);
int choice = option.nextInt();


switch(choice)
{
case 1:
table();
break;
case 2:
evenOdd();
break;
case 3:
dataTypes();
break;
case 4:
gradePrint();
break;
case 5:
sum();
case 6:
factorial();
break;
case 7:
reverse();
break;
}
}
public static void table()
{
int n=5;
System.out.println("Table of 5:");
for(int i=1; i<=10; i++)
{
System.out.println(n+  "*"  + i +" = " +(n*i));
}
}
public static void evenOdd()
{
int i;
for(i=1; i<=10 ; i++)
{
if(i%2==0)
System.out.println("Even number of :" +i);

}
for(int u=1; u<=10 ; u++)
{
if(u%2==1)
System.out.println("odd number of :" +u);
}
}
public static void dataTypes()
{
byte bytePrint = 100;
short shortPrint = 5000;
int intPrint = 100000;
        long longPrint = 15000000000L;
        float floatPrint = 5.75f;
        double doubleValuePrint = 19.99d;
char myGrade = 'B';
        boolean booleanValuePrint = true;
        String name = "Usamn Hashmi";


          System.out.println(bytePrint);
  System.out.println(shortPrint);
  System.out.println(intPrint);
  System.out.println(longPrint);
  System.out.println(floatPrint);
  System.out.println(doubleValuePrint);
  System.out.println(booleanValuePrint);
  System.out.println(myGrade);
  System.out.println(name);
}
public static void gradePrint()
{
int marks = 90;
if(marks>=90)

System.out.println("Your grade is : A");
else if(marks==80&&marks<90)

System.out.println("Your grade is : B");
else if(marks==70&&marks<80)

System.out.println("Your grade is : C");
else if(marks==60&&marks<70)

System.out.println("Your grade is : D");
else

System.out.println("Your grade is : F");



}
public static void sum()
{
int sum=0;
for(int i=1 ;i<=10 ; i++)
sum=sum+i;
System.out.println("The sum of first ten numbers:" +sum);
}
public static void factorial()
{
  int i,fact=1;
          int number=5; //<= This number find factorial 
            for(i=1;i<=number;i++)
 
                fact=fact*i;     
                System.out.println("Factorial of "+number+" is: "+fact); 

}
public static void reverse()
{
int num = 1002, reverved = 0;
        while(num != 0)
{
            int remainder = num % 10;
            reversed = reversed * 10 + remainder;
            num /= 10;
        }
        System.out.println("Reversed Number: " + reversed);
}

}

Post a Comment

0 Comments