The below program shows how to use array and store student’s details and fetch details. Here we are using for each loop which is used to iterate throughout entire array element. Example import java.util.Scanner; class FindGrade { //get roll number and marks of student and calculate percentage and grade public static void main(String args[]) { int sub[],i,total=0; float per=0.0f; Scanner sc; String rNo; sub=new int[5]; sc=new Scanner(System.in); System.out.println("Enter Roll Number"); rNo=sc.next(); for(i=0;i<5;i++) { System.out.println("Enter Marks Of Subject "+(i+1)); sub[i]=sc.nextInt(); total=total+sub[i]; } per=total*100/500; System.out.println("\n***** Details Of Student *****\n"); System.out.println("\nRoll Number "+rNo); System.out.println("Total Marks Gained Is "+total); System.out.println("Percentage Gained Is "+per); if(per>90)…
-
-
The below program performs arithmetic and bitwise operations based on number entered by user. Scanner class is used to take input from the user, which is inside java.util.Scanner class. System.in is used to use input classes. Example import java.util.Scanner; class ArithmeticOperation { //arithmetic operation on float data public static void main(String args[]) { int n1,n2; int fChoice; Scanner sc=new Scanner(System.in); System.out.println("Select Choice\n"); System.out.println("1. Arithmetic Operation"); System.out.println("2. Bitwise Operation"); System.out.println("Enter Your Choice"); fChoice=sc.nextInt(); System.out.println("\nEnter First Value"); n1=sc.nextInt(); System.out.println("Enter Second Value"); n2=sc.nextInt(); switch(fChoice) { case 1: ArithmeticOp(n1,n2); break; case 2: BitwiseOp(n1,n2); break; default: System.out.println("Invalid Choice"); break; } } public static void ArithmeticOp(int…
-
In this program, we iterate the loop and print Fizz when the current number is multiple of 3, and print Bizz when the current number is multiple of 5, and print Fizz-Bizz when the current number is multiple of 3 and 5. The below example illustrate this. Example class FizzBizzDemo { //print fizz when number is multiply by 3 and bizz when number is multiply by 5 and for both print fizz-bizz public static void main(String args[]) { int i; for(i=0;i<=50;i++) { if(i%3==0 && i%5==0) { System.out.println(i+" - Fizz-Bizz"); } else { if(i%3==0) { System.out.println(i+" - Fizz"); } else if(i%5==0)…
-
In this we are taking date, month and year with three different variable and then check whether the date is valid or not. The below program shows how to check whether the data value is valid or not. Example import java.util.*; class GetBirthDate { //get the birthdate of his or her public static void main(String args[]) { int dt,month,year,leap=0,noOfDay=0; Scanner sc=new Scanner(System.in); System.out.println("Enter Birth Year"); year=sc.nextInt(); if(year>2019) { System.out.println("Year Is Invalid Please Enter Proper Year"); } else { if(year%4==0) { leap=1; } System.out.println("Enter Birth Month"); month=sc.nextInt(); switch(month) { case 1: noOfDay=31; break; case 2: if(leap==1) noOfDay=29; else noOfDay=28; break; case…
-
Character is stored in its ASCII format in java. The standard set of character known as ASCII still ranges from 0 to 127 as always. Example: import java.util.Scanner; class FindASCII { //get ASCII value of character public static void main(String args[]) { char c,con; int i; Scanner sc; do { sc=new Scanner(System.in); System.out.println("Enter Any Character"); c=sc.next().charAt(0); i=c; System.out.println("ASCII Value Of "+c+" Is "+i); System.out.println("Do You Want To Continue (y/n) "); con=sc.next().charAt(0); }while(con=='y' || con=='Y'); } } OutPut Enter Any Character T ASCII Value Of T Is 84 Do You Want To Continue (y/n) n
-
In java boolean datatype is used to take value true or false. This is the type that is returned by all relational operators, as in the case a<b. boolean is also required by conditional expressions that govern the control statement such as if and for. In previous we learn about primitive datatype which give introduction of basic java’s data type. We know that boolean only take the value either true or false. Unlike in C where the boolean also takes 0 and 1 to determine false and, true this is the not case in java. Example The below example shows…
-
The basic primitive datatypes are listed below. Integer Floating Point Character Boolean Here this types also categorized in other datatypes as follow. Integer This all stores signed, positive and negative values. byte short int long Floating Point Floating Point also known as real number are used when evaluating expression that require fraction precision. float double Character take ASCII value. In java char is 16 bit type. The range of char is 0 to 65535. There is no negative char. In java, boolean data type we cannot assign 0 or 1 or any numeric value to determines true or false. It…