Skip to main content

Java Projects

How to Make Basic Java programs:




Java is one of the best programming language to make GUI and many other departmental software for making computer handling software . Through java programming you can make games , calculators , ticket Machine and related software because it deals with some wide range of built in functions which every programming language do exist..







Here below is the Code through which you can easily make some basic four programs :


Even or Odd :


import java.util.Scanner;
public class EvenorOdd
{
 public static void main(String Args[])
 {
  int x;
  System.out.println("Enter the number");
  Scanner input = new Scanner(System.in);
  x=input.nextInt();
  
  if(x % 2 ==0)
   System.out.println("The number is even");
  else
   System.out.println("The number is odd");
 }
}



Radius :


import java.util.Scanner;
public class Radius {
 public static void main(String[] args) {
  Scanner scn= new Scanner(System.in);
  float rad;
  System.out.print("Please Enter Radius of a Circle: ");
  rad = scn.nextFloat();
  
  float pi = (float) Math.PI;
  float diam = 2*rad;
  float cir = 2*pi*rad;
  float area = pi*(rad*rad);
  
  System.out.printf("A Circle of Radius %s has: Diameter: %s Circumference: %s Area: %s ", rad, diam, cir, area); 
 }
}



Maximum and Minimum value :
import java.util.Scanner;

public class MaxMin
{
 public static void main(String arg[])
 {
  Scanner cp = new Scanner (System.in);
  
  int inputVal;
  int max = 0;
  int min = 0;

  for(int i=1; i<=5;i++)
  {
   System.out.println(String.format("Enter Value #%s: ", String.valueOf(i)));
   inputVal = cp.nextInt();
   if(i==1)
   {
    min = inputVal;
    max = inputVal;
   }
   if(inputVal > max) {
    max = inputVal;
   }
   if(inputVal < min)
   {
    min = inputVal;
   }
  }
  System.out.println(String.format("Max Value is %s.", max));
  System.out.println(String.format("Min Value is %s.", min));
 }
}


Spacing between digits :
import java.util.Scanner;

public class Spacing{
 
 public static void main(String[] args) {
  Scanner scn= new Scanner(System.in);
  
  int i;
  int maxminAllowed= 5;
  
  System.out.print("Enter 5 Digits: ");
  i = scn.nextInt();
   
  String s = String.valueOf(i);
  int charCount = s.length();
  
  if(charCount == maxminAllowed)
  {
   char[] charss  = s.toCharArray();
   System.out.printf("%s \t %s \t %s \t %s \t %s",charss[0],charss[1],charss[2],charss[3],charss[4]);
  }else if(charCount > maxminAllowed){
   System.out.printf("You can not enter Numbers Greater than %s", maxminAllowed);
   System.out.println("");
   main(args);
  }else {
   System.out.printf("You can not enter Numbers Less than %s", maxminAllowed);
   System.out.println("");
   main(args);
  }
 }
}

    


Keep Sharing !

Comments

Popular posts from this blog

Technology

Virtual Reality The Next Upcoming Domain in Pakistan is VIRTUAL REALITY and people are making themselves obsessed with it because it takes your imagination to what you are seeing through VR gadget as we know the technology is going to boom in Pakistan through last few years.

Program to Make Canvas in Java For GUI

GRAPHICAL USER INTERFACE : CANVAS CLASS: import javax.swing.*; import java.awt.*; import java.util.List; import java.util.*; /**  * Canvas is a class to allow for simple graphical drawing on a canvas.  * This is a modification of the general purpose Canvas, specially made for  * the BlueJ "shapes" example.   *  * @author: Bruce Quig  * @author: Michael Kšlling (mik)  *  * @version 2011.07.31  */ public class Canvas {     // Note: The implementation of this class (specifically the handling of     // shape identity and colors) is slightly more complex than necessary. This     // is done on purpose to keep the interface and instance fields of the     // shape objects in this project clean and simple for educational purposes.     private static Canvas canvasSingleton;     /**      * Factory method to get t...

Virtual reality

VIRTUAL REALITY: A BLESSING INTRODUCTION At the beginning of 1990s the development in the field of virtual reality became much more stormy and the term Virtual Reality itself became extremely popular. We can hear about Virtual Reality nearly in all sort of media, people use this term very often and they misuse it in many cases  too. The reason is that this new, promising and fascinating technology captures greater interest of people than e.g., computer graphics. The consequence of this state is that nowadays the border between 3D computer graphics and Virtual Reality becomes fuzzy.Virtual reality is the creation of a virtual environment presented to our senses in such a way that we experience it as if we were really there. It has both entertainment and serious uses. The technology is becoming cheaper and more widespread. We can expect to see many more innovative uses for the technology in the future and perhaps a fundamental way in which we communicate and work t...