Basic Programs
Below programs will
print,
1. Simple output.
2. Address.
3. Values.
4. Symbols.
5. Tab space in ouput
6. Diff b/n Sop and Sopln
------------------------------------------------------------------------------------------
Program 1 :
Java program to print simple text
Program name :
Welcome.java
Output :
Welcome to Java
class Welcome
{
public static void main(String args[])
{
System.out.println("Welcome to Java");
}
}
Compile
: javac Welcome.java
Run
: java Welcome
Output :
Welcome
to Java
------------------------------------------------------------------------------------------
Program name :
CollegeAddress.java
Output :
----College Address starts----
Y.V.N.R Govt Degree College
Kaikaluru
Krishna District
Andhra Pradesh
Pin Code : 521345
----College Address end-----
class CollegeAddress
{
public static void main(String args[])
{
System.out.println("----College Address
starts----");
System.out.println("Y.V.N.R Govt Degree
College");
System.out.println("Kaikaluru");
System.out.println("Krishna District");
System.out.println("Andhra Pradesh");
System.out.println("Pin Code : 521345");
System.out.println("----College Address
end-----");
}
}
Compile
: javac CollegeAddress.java
Run
: java CollegeAddress
Output :
----College Address starts----
Y.V.N.R
Govt Degree College
Kaikaluru
Krishna
District
Andhra
Pradesh
Pin Code
: 521345
----College Address end-----
------------------------------------------------------------------------------------------
Program name :
ValueDemo.java
Output :
123
1.234
class ValueDemo
{
public static void main(String args[])
{
System.out.println(123);
System.out.println(1.234);
}
}
Compile
: javac ValueDemo.java
Run
: java ValueDemo
Output :
123
1.234
------------------------------------------------------------------------------------------
Program 4 :
Java program to print symbols
Program name :
SymbolsDemo.java
Output :
Symbols : +, - , * , / , %
class SymbolsDemo
{
public static void main(String args[])
{
System.out.println("Symbols :
+, - , * , / , %");
}
}
Compile
: javac SymbolsDemo.java
Run
: java SymbolsDemo
Output :
Symbols : +, - ,
* , / , %
------------------------------------------------------------------------------------------
Program name :
TabSpaceDemo.java
Output
:
I given five tab spaces before print
class TabSpaceDemo
{
public
static void main(String args[])
{
System.out.println(" I
given five tab spaces before print");
}
}
Compile
: javac TabSpaceDemo.java
Run
: java TabSpaceDemo
Output :
I given five tab spaces before print
------------------------------------------------------------------------------------------
Program 6 :
Difference b/n Sop and Sopln
Program name :
SopAndSopln.java
Output
:
One
TwoThree
class SopAndSopln
{
public static void main(String args[])
{
System.out.print("Two");
System.out.println("Three");
}
}
Compile
: javac SopAndSopln.java
Run
: java SopAndSopln
Output :
One
TwoThree
------------------------------------------------------------------------------------------
Thanks for your time.
- Nireekshan