Skip to main content

Posts

Java Program to swap the values of a and b

import java.io.*; import java.util.*; public class  Swap{     public static void main(String[] args)throws IOException{         Scanner scan=new Scanner(System.in);         int a,b,c;         System.out.println("Enter the value of a: ");         a=scan.nextInt();         System.out.println("Enter the value of b: ");         b=scan.nextInt();         System.out.println("Value of a "+a);         System.out.println("Value of b "+b);         c=b;         System.out.println("After:-\nValue of a: "+c);         b=a;         System.out.println("Value of b: "+b);...

Java Program using Menu Driven criteria develop a Calculator

import java.io.*; import java.util.*; public class Calculator{     public static void main(String[] args)throws IOException{         double a,b,res=0;         int choice,ch;         Scanner scan=new Scanner(System.in);         do{             System.out.println("MENU");             System.out.println("Enter 1 for Addition.");             System.out.println("Enter 2 for Substraction.");             System.out.println("Enter 3 for Multiplication.");             System.out.println("Enter 4 for Division.");           ...

Java Program to accept the marks of n students' one subject and display the total and average

The following code is to accept the details on 'n' number(s) of student(s) and display the total and the average of all. Maximum students are 60,000 and can be increased by increasing the array size. Code:- import java.util.*; public class Marks{     Scanner scan=new Scanner(System.in);     String name[]=new String[60000];     String sub[]=new String[60000];     int roll[]=new int[60000];     int marks[]=new int[60000];     int total, students;     int i,e;     float average;     public void input(){         try{             System.out.println("Enter the total number of students: ");             students=scan.nextInt();             for(i=1;...

Java Program to calculate the Library Fine and display in a nice format

import java.io.*; public class Library{     int acc_num,edays,fine;     String author, title;     BufferedReader buff=new BufferedReader(new InputStreamReader(System.in));     public void input()throws IOException{         System.out.println("Enter the Accssion Number:- ");         acc_num=Integer.parseInt(buff.readLine());         System.out.println("Enter the Author Name:- ");         author=buff.readLine();         System.out.println("Enter the Title of the Book:- ");         title=buff.readLine();         System.out.println("Enter the Extra Days:- ");         edays=Integer.parseInt(buff.readLine());     }     public vo...

Java Program to search a number within the list using Binary Search method

import java.io.*; import java.util.*; public class Binary{     Scanner scan=new Scanner(System.in);     int beg,mid,last,flag=0,n;     int list[]={1,3,5,7,8,9,13,15,19,24,27,29,30,33,35,36,39,43,47,51,53,60};     public void input()throws IOException{         System.out.print("Enter any number for Searching: ");         n=scan.nextInt();         compute(n);     }     public void compute(int n){         beg=0;         last=21;         while(beg<=21){             mid=(beg+last)/2;             if(n>list[mid])             ...

Java Program to show the use of "this" keyword

import java.io.*; public class Demo_This{     static int a;     public void display(int a){         a=10;//local variable.         this.a=20;//Global variable.         System.out.println(a);         System.out.println(this.a);     }     public static void main(String[] args)throws IOException{         Demo_This obj=new Demo_This();         obj.display(a);     } }

Java Program to display the Multiplication Table of a number upto a limit

import java.io.*; import java.util.*; public class MultiplicationTable{     Scanner scan=new Scanner(System.in);     int number, limit, i;     public void input(){         try{             System.out.println("Enter the number: ");             number=scan.nextInt();             System.out.println("Enter the limit: ");             limit=scan.nextInt();         }         catch(Exception e){             System.out.println("Error Code: "+e);             System.exit(0);         }  ...