Tuesday, October 1, 2019

How to use class in java program


//class 
class student
{
String name;
int roll_no;
}
//main class
class ans
{
//main function
public static void main(String args[])
{
//object declaration
student s = new student();
s.name = "John";
s.roll_no = 18;
//print function
System.out.println("Name is" +s.name+ "and roll number is" +s.roll_no);
}
}

Output : Name is John and roll number is 18.

Tuesday, September 24, 2019

Use of For Loop in Java Programming


// main class 
class multiple{// void functionpublic static void main(String[] args){
// variable declaration
int a,b,c;
a=20;
// For loop
for(b=1; b<=10;b++)
{
// multiple operator
c=a*b;
//output printing function on screen
System.out.println("a*b="+c);
}
}
}
output : 20;
             40;
             60;
             80;
             100;
             120;
             140;
             160;
             180;
             200;

Monday, September 23, 2019

How to use of Operator in java


// main class
public class second
{
// main function
public static void main(String args[])
{
//variable declaration
int a,b,c,d,e,f;
a=30;
b=20;
// operator use 
c=a*b;
d=a+b;
e=a-b;
f=a/b;
// print function
System.out.println("a*b="+c);
System.out.println("a+b="+d);
System.out.println("a-b="+e);
System.out.println("a/b="+f);
}
}

output : a*b : 600;
             a+b : 50;
             a-b :  10;
             a/b :   1.5;

Friday, September 20, 2019

Swap two number using third variable.

// main class
public class swap
{
// void main function
public static void main(String[] args)
{
//variable declaration
int a,b,temp;
a=10;
b=20;
//by this method number would swap
temp=a;
a=b;
b=temp;
// print method
System.out.println("b="+b);
System.out.println("a="+a);
}
}

Thursday, September 19, 2019

Type your Input in Java program

// main class 
class input
{
// main function
public static void main(String args[])
{
//print function
System.out.println("hello");
System.out.println(args[0]);
}
}

Output :- Hello 
               Type any name.

Wednesday, September 18, 2019

First hello world java program



//Declaration of class
class welcome
{
//main function
public static void main(String args[])
{
//print function
System.out.println("Hello World");
}
}

Output: Hello World.