AIM: write a program to print hello world in java. CODE : : //please save this code as Hello.java or download the given file and compile it with " javac Hello.java " //After successful compilation run this with " java Hello " at CMD // Make sure you have java already //installed in your system class Hello { public static void main(String m[]) { System.out.println("Hello world"); } } OUTPUT : : Hello world thankyou for reading this, please share my blog for future updates and more and more programs. Thankyou...
//please save this code as UserInput.java or download the given file and compile it with " //javac UserInput.java " //After successful compilation run this with " java UserInput " at CMD // Make sure you have java already //installed in your system CODE : : import java.util.*; class UserInput { public static void main(String arg[]) { int a,b,c; Scanner m=new Scanner(System.in); System.out.println("Enter value of A:"); a=m.nextInt(); System.out.println("Enter value of B:"); b=m.nextInt(); c=a+b; System.out.println("Addition of two numbers is:"+c); } } OUTPUT : :
//please save this code as InrtoUsd.java or download the given file and compile it with " //javac InrtoUsd.java " //After successful compilation run this with " java InrtoUsd " at CMD // Make sure you have java already //installed in your system CODE : : import java.util.*; class InrtoUsd { public static void main(String m[]) { double inr,usd; Scanner in=new Scanner(System.in); System.out.println("Enter INR to convert into USD:"); inr=in.nextInt(); usd=inr/60; System.out.println("INR="+inr+" is USD="+usd); } } OUTPUT : :
//please save this code as Calc.java or download the given file and compile it with " javac Calc.java " //After successful compilation run this with " java Calc " at CMD // Make sure you have java already //installed in your system CODE : : import java.util.*; class Calc { public static void main(String m[]) { Scanner in=new Scanner(System.in); int a,b,c=0; String o=new String(); System.out.println("Enter value of A:"); a=in.nextInt(); System.out.println("Enter value of B:"); b=in.nextInt(); System.out.println(" Enter + for addition \n Enter - for subtraction \n Enter * for multiplication \n Enter / for division"); System.out.println("\nEnter Your Choice::"); o=in.next(); switch(o) { case "+": c=a+b; break; case "-": c=a-b; break; case "*": c=a*b; break; case "/": c=a/b; break; default: System.out.println("Invalid choice"); } System.out.println("The answer is :"+c); } } OUTPUT : :
//please save this code as Array.java or download the given file and compile it with " javac Array.java " //After successful compilation run this with " java Array " at CMD // Make sure you have java already //installed in your system CODE : : import java.util.*; class Array { public static void main(String m[]) { Scanner in=new Scanner(System.in); int n; System.out.println("How many number of elements"); n=in.nextInt(); int a[]=new int[n]; for(int i=0;i<n;i++) { System.out.println("Enter "+(i+1)+" no. of Element"); a[i]=in.nextInt(); } for(int i=0;i<n;i++) { System.out.println("THe value on position "+(i+1)+" is: "+a[i]); } } } OUTPUT : :
E-books of JAVA use ebook, save money, eat more, work hard, do well :D below is 9th edition
below is 7th edition
//please save this code as Prog4.java or download the given file and compile it with " javac Prog4.java " //After successful compilation run this with " java Prog4 " at CMD // Make sure you have java already //installed in your system CODE : : class Prog4 { public static void main(String s[]) { int a=5,b=6; System.out.println("The value of A is:"+a+" & value of B:"+b); if(a>b) { System.out.println("A("+a+") is bigger"); } else { System.out.println("B("+b+") is bigger"); } } } OUTPUT : : B(6) is bigger
This program takes one arguments statically and generates table from 1 to that number. //please save this code as Prog3.java or download the given file and compile it with " javac Prog3.java " //After successful compilation run this with " java Prog3 " at CMD // Make sure you have java already //installed in your system CODE : : class Prog3 { public static void main(String s1[]) { int a=3,c; for(int n=1;n<=a;n++) { System.out.println("Start of table:"+n); for(int b=1;b<=10;b++) { c=n*b; System.out.println(n+"*"+b+"="+c); } System.out.println("End of table:"+n); } } } OUTPUT : :
|
Hello friends, i am a CSE student and i am going to upload all the programs of various language which might be in your collage practical list or might help you in performing your practicals in lab. Archives
August 2015
Categories |