Sei sulla pagina 1di 4

Difference Between the print and println

The print("aString") method prints just the string "aString", but does not move the cursor to a
new line. Hence, subsequent printing instructions will print on the same line.
The println("aString") method prints the string "aString" and moves the cursor to a new line

File Name should be same as main method Class

Program 1:

class Os

int rollno;

String name;

void insertRecord(int r, String n)

rollno=r;

name=n;

void displayInformation()

System.out.println(rollno+" "+name+" "+"output is");

//System.out.println(rollno);

//System.out.println(name);

class Student

public static void main(String args[])

{
Os s1=new Os();

Os s2=new Os();

s1.insertRecord(111,"Karan");

s2.insertRecord(222,"Aryan");

s1.displayInformation();

s2.displayInformation();

}
/*

Ex:4 : Using Command Line Input

Aim: Creating a java program to get input by Command Line Input.

How to Run:

G:\javaaac>javac cla.java

G:\javaaac>java cla xxxx 111 2


The java command-line argument is an argument i.e. passed at the time of running the java
program

*/

import java.io.*;

public class commandline_4

public static final void main(String args[])

int a, b, c; String name;

name=args[0];

a=Integer.parseInt(args[1]);

b=Integer.parseInt(args[2]);

c=a+b;

System.out.println( "Given Name : "+name );

System.out.println( "Value of A : "+a );

System.out.println( "Value of B : "+b );

System.out.println( "The Sum of C : "+c );


}

Potrebbero piacerti anche