Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Friday, 25 July 2014

Examples of loop with output in java code

class Loops
{
                public static void main(String args[])
                {
                                int i;
                                for(i=0; i<10; i += 2)
                                System.out.print(" " + i);
                                System.out.println();

                                for(i=100; i>=0; i -= 7)
                                System.out.print(" " + i);
                                System.out.println();

                                for(i=1; i<=10; i += 1)
                                System.out.print("*" + ++i);
                                System.out.println();

                                for(i=2; i<100; i *= 2)
                                System.out.print(" " + i);
                }
}
Output:
0 2 4 6 8
100 93 86 79 72 65 58 51 44 37 30 23 16 9 2
*2*4*6*8*10

2 4 8 16 32 64

Thursday, 24 July 2014

Calculate square of odd, cube of even , quotient for multiple of 7 with java code.

import javax.swing.*;
class Cal
{
                public static void main(String args[])
                {
                                int n;
                                n = Integer.parseInt(JOptionPane.showInputDialog("enter a value: "));
                                if (n%2==0)
                                {
                                System.out.println("cube of even value = " + n*n*n);
                                JOptionPane.showMessageDialog(null, "cube of even value = " + (n*n*n));
                                }
                                else if (n%2!=0)
                                {
                                System.out.println("square of odd value = " + n*n);
                                JOptionPane.showMessageDialog(null, "square of odd value = " + (n*n));
                                }
                                if (n%7 == 0)
                                {
                                System.out.println("quotient for 7 is " + n/7);
                                JOptionPane.showMessageDialog(null,"quotient for 7 is " + (n/7));
                                }
                                System.exit(0);
                }

}

Wednesday, 23 July 2014

Show first 10 Fibonacci numbers in message dialog box with java code.

import javax.swing.*;
class Fibo
{
                public static void main(String[] args){
                int n1 = 0,n2 = 1,n3;
                String st;
                st = n1 + "\n" + n2 + "\n";
                for(int i = 1; i<10; i++){
                                n3 = n1 + n2;
                                st += ( n3 + "\n");
                                n1 = n2;
                                n2 = n3;
                }
                JOptionPane.showMessageDialog(null, st);
                System.exit(0);
                }                             

}

Monday, 21 July 2014

What is Java?

The word java is a long term of coffee. Java is a purely object oriented programming. It enhances and refines the object oriented paradigm used by C++. In internet programming, Java is a revolutionary force that will change the world, as similar like C was in system programming. The main objective behind the development of Java is portability and plat form independents language.
So that it could produce such type of codes that would run on variety of CPUs under different environment.
            As C++ provides this facility but for running a program of C++ on any type of CPU we need a full C++ compiler on that particular CPU. But the problem is that the compilers are expense and time consuming to create.

            Java is both interpreter and compiler based language. 

Thursday, 17 July 2014

Write, save, compile and run simple java program in command prompt.

Write, save, compile and run simple java program in command prompt.

step 1

open notepad.

step 2

write any code for java program.

save with java format in bin folder of jdk.

step 3

open cmd and go to bin folder.

step 4

use javac command to compile java file
after compilation class file will be created.

step 5

use java command to run java program(class file).

keep visiting www.h-programmer.blogspot.com for more interesting posts.
thank you.



java by Hamayun Aziz