Sunday 25 September 2016

Pop Ups in JAVA

import javax.swing.JOptionPane;
public class stringvar
{
public static void main(String args[])
{
String fn,fn2,fn3;      
fn = JOptionPane.showInputDialog("Enter your first name");
fn2= JOptionPane.showInputDialog("Enter your family name");

fn3 = "You are "+ fn+" "+fn2;
JOptionPane.showMessageDialog(null,fn3);
}
}






Sunday 18 September 2016

A CODE that finds the greatest number among three


import java.util.Scanner;
class G
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
int a,b,c;
System.out.println("Enter the three numbers ");
a=in.nextInt();                                  
b=in.nextInt();                             // taking three inputs from user
c=in.nextInt();
if(a!=b&&b!=c&&c!=a){          // Checking whether there is more than one same input
if(a>b&&a>b)                             //Checking for first number
System.out.println(a+" is greatest");
else if(b>a&&b>c)                       //Checking for second number
System.out.println(b+" is greatest");
else                                              // In case all conditions are false the third condition becomes true
System.out.println(c+" is greatest");
}
else
System.out.println("One or more numbers are equal ;try again ");
}
}



CODE to reverse a number in JAVA

import java.util.Scanner;   // Scanner class is impoerted to perform input functions
class Rev
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);   // Creating Object of Scanner Class
int s=0,n,r;            
n=in.nextInt();    // Taking input form user and storing in 'n' variable.
while(n!=0)
{
r=n%10;             // remainder is determined(if n is 998 then r will be 8)
s=s*10+r;          
n=n/10;
}
System.out.println("Revers is "+s);
}
}




Thursday 8 September 2016

Passing an attribute through main method

class CmdLimit  // Creating a class
{
public static void main(String args[])   //Arguments would be passed through main.                            {
int n,i;
n =  args.length;   // length of the argument is stored in n
for(i=0;i<n;i++)
{
System.out.println("Arguement" +i+" "+args[i]);      //arguments would be printed one by one
}
}
}


or Goto BlueJ





Tuesday 6 September 2016

Area of Rectangle - Functions and classes in JAVA an introduction

Class - In JAVA class is a way to bind functions and objects together in a single unit.
unlike C it requires no header files.
Functions - Functions are a self contained block of statements, that perform a specific task.
import java.util.Scanner;

class Rectangle // it's a custom to write the first letter of class in Capitals.

{

int height,breadth; // Global variables

void getData(int x,int y)  // x and y are the formal parameters

{

height = x;

breadth= y;

}

int area()

{

return breadth*height;

}

}

class Rectangle2   // another class(Main class because main function is in this class)

{

public static void main(String args[])

{

Scanner in = new Scanner (System.in);

int z,h,g;

System.out.println("Enter the height and breadth");

h= in.nextInt();

g= in.nextInt();

 Rectangle e = new Rectangle();

 e.getData(h,g);

 z = e.area();

 System.out.println("Area is "+z);

 }

 }


1. Open terminal in case of linux
2. set the path
3. type javac  classname.java
4. java classname