[Java] Program to find factorial of the given number


import java.util.Scanner; public class Main{public static void main(String[] args) {    Scanner scanner = new Scanner(System.in);            int  number = scanner.nextInt();            int fact = 1;                        while(number != 0)            {                fact *= number–;                           }            System.out.println(fact);    }}

[Java]How to display Unicode symbol in Java


Unicode symbols are listed in this link http://www.unicode-table.com/en/#00 To get the Unicode number Click on the symbol which you want to print eg : – unicode number for @ is U+0040  which in java is u0040 Below the code segment to print Unicode “@”  on screen System.out.println(“\u0040”); Note : Don’t forget to give  \  Continue reading “[Java]How to display Unicode symbol in Java”

[Java] compiler Error fix for – “The public type <> must be defined in its own file”


If this is the error you are facing while compiling java code , Then Change public class classname to class classname This is because java rule suggests that one public class in one file

[Java][Linux]How to run Hello World program


Create file named HelloWorld_javapgm The content of the file HelloWorld.java is class hello { public static void main(String args[]) { System.out.println(“Hello World”); } } run the following command javac HelloWorld.java which will create hello.class run the following command java hello which will print the string Hello World

[Java]Important things to remember


Father of Java – James Gosling Java created by SUN MICRO SYSTEMS Earlier name of Java – OAK Java was targeted for Internet Development Java is currently owned by ORACLE Corporation C# is closely related to Java Java is purely Object oriented program ByteCode – The intermediate code created by the Java compiler JVM  JavaContinue reading “[Java]Important things to remember”

java program for finding leap year


public class leapYear { public static void main (String[] args) { boolean leapYear; int val; // Check whether args[0] is null or not if( args.length == 0) { System.out.println(“Usage- java leapYear Year . Eg: java leapYear 1984″); System.exit(0); } else { val = Integer.parseInt(args[0]); leapYear = (((val % 4 == 0 ) && (val %Continue reading “java program for finding leap year”

[Java]Finding solution for quadratic equation using java


public class SolnForQuadraticEqn { public static void main (String[] args) { double a = 0; double b = 0; double c = 0; double iVal1 = 0; // Three args expected . Check whether args.length is 3 if( args.length < 3) { System.out.println(“Usage- java SolnForQuadraticEqn a b c (considering the quadratic equation ax2 + bxContinue reading “[Java]Finding solution for quadratic equation using java”

[Java] program for printing sine value for every 15 deg from 0 to 360


/* * This program will print sine value for every 15 deg from 0 to 360 * degree should be converted to radians before passing as an arguement to Math.sin * 1 degree = pi/180 radian */ public class sineFunc{ public static void main(String[] args) { double degrees = 0.0; for(; degrees <= 360.0 ;Continue reading “[Java] program for printing sine value for every 15 deg from 0 to 360”

[Java]Steps to run java program in Windows


Install JDK set path environment variable for Java right click on my computer -> Advanced->Environment Variables->path Add the following in the variable value of path after putting a semicolon C:\Program Files\Java\jdk1.7.0_10\bin (or the location where JDK installed) Compiling java program compiler used for compiling java program is javac javac AbsolutePathToFile This command will create aContinue reading “[Java]Steps to run java program in Windows”