Posts

Showing posts from March, 2017

JAVA Basic Programs -- Sum of Two Numbers

Image
Sum of two numbers by receiving value from keyboard    In this program we use two variables which receive value from the keyboard and add those values and sum of these numbers are stored in the third variable. In this example we are using Scanner, Scanner is a class in java.util package used for obtaining the input of the primitive types like int, double etc. and strings. It is one of the ways to read input in a Java program. Syntax for scanner... Declare the object and initialize with predefined standard input object Scanner sc = new Scanner(System.in); String input        String name = sc.nextLine(); Character input char gender = sc.next().charAt(0); Numerical data input byte, short and float can be read using similar-named functions.        int age = sc.nextInt();  long mobileNo = sc.nextLong();  double cgpa = sc.nextDouble(); Xample: File_name: Addition .java For Compiling: javac Addition.java For Execution: java ...

JAVA Basic Programs -- Sum Of Two Numbers

Image
In this program, we use two variables which have already contain values and sum of these numbers are stored in the third variable. Xample : File_name : Addition.java For Compiling : javac   Addition.java For Execution : java   Addition Remember filename and class name must be the same class Addition {      public static void main(String[] args)     {          int a=10, b=20, c=0;          c=a+b;          System.out.println("Sum: "+c);     } } OutPut: Sum: 30 That's it, I hope it is useful. Thanks For reading.

JAVA Basic Programs -- Hello World in Java

Image
This is your first java program, simply write in any editor and save your code with finename.java and after saving program compile using javac tool and run by using java tool. Xample:  File_name : Helloworld.java For Compiling : javac helloworld.java For Execution : java Helloworld Remember filename and class name must be the same Xample : class Helloworld {   public static void main(String[] args)   {     System.out.println("Hello World!");   } } System.out.println("....."): are used for display message on screen or console. Output : Hello World! That's it, I hope it is useful. Thanks For reading.