0% found this document useful (0 votes)
4 views7 pages

Java Programming Basics and Examples

The document provides several Java code examples demonstrating basic programming concepts such as printing 'Hello World', adding numbers using command line arguments and user input, finding the greatest among three numbers, creating a simple calculator, and generating multiplication tables. Each example includes the code and a brief description of its functionality. The document serves as a beginner's guide to Java programming with practical applications.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views7 pages

Java Programming Basics and Examples

The document provides several Java code examples demonstrating basic programming concepts such as printing 'Hello World', adding numbers using command line arguments and user input, finding the greatest among three numbers, creating a simple calculator, and generating multiplication tables. Each example includes the code and a brief description of its functionality. The document serves as a beginner's guide to Java programming with practical applications.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Oops with java

1. Hello world:
Code:
class vijayhello {
public static void main (String []args){
[Link]("hello, world!");
}
}
Output:

2. Add using args:


Code:
class vijayadd{
public static void main (String []args){

int a= [Link](args[0]);
int b= [Link](args[1]);
[Link](a+b);
}
}
Output:

3. Add using input:


Code:
import [Link].*;
class vijayaddin{
public static void main (String []args){
Scanner kb =new Scanner([Link]);
[Link]("enter first num:");
int a= [Link]();
[Link]("enter second num:");
int b= [Link]();
[Link]("sun :");
[Link](a+b);
}
}
Output:
4. greatest among three:
code:
import [Link].*;
class vijaygre{
public static void main (String []args){
Scanner kb =new Scanner([Link]);
[Link]("enter first num:");
int a= [Link]();
[Link]("enter second num:");
int b= [Link]();
[Link]("enter third num:");
int c= [Link]();
[Link]("greatest among three :");
if(a>b&&b>c){
[Link](a);
}else if(b>a&&a>c){
[Link](b);
}
else{
[Link](c);
}

}
}
output:

5. calculator
code:
import [Link].*;
class vijayswitch{
public static void main (String []args){
Scanner kb =new Scanner([Link]);
[Link]("enter first num:");
int a= [Link]();
[Link]("enter second num:");
int b= [Link]();
[Link]("enter opration:");
[Link] ("[Link];");
[Link] ("[Link];");
[Link] ("[Link];");
[Link] ("[Link];");
int c= [Link]();
switch(c){
case 1:
[Link] (a+b);
break;
case 2:
[Link] (a-b);
break;
case 3:
[Link] (a*b);
break;
case 4:
[Link] (a/b);
break;
}

}
}
Output:

7 . table
Code:
import [Link].*;
class vijaytable{
public static void main (String []args){
int a= [Link](args[0]);
int b= [Link](args[1]);
for(int j=1;j<=10;j++){
for(int i=a;i<=b;i++){
[Link]("\t %d" , (i*j ));

}
[Link]();
}

}
}
Output:

You might also like