source file name: simpleoo1.java class simpleoo1 { int a,b; void get(int m, int n) { a=m; b=n; } void show() { System.out.println(" a: "+a+" b: "+b); } public static void main(String dbj[]) { System.out.println("object oriented program: "); simpleoo1 ob1=new simpleoo1(); simpleoo1 ob2=…
Read more6) Write a Java program that interchange two values swap method and display these two numbers using disp method.
source file name: simple1.java class Swap { int a,b; void set(int m,int n) { a=m; b=n; } void show() { System.out.println("a="+a+" b="+b); } void swap() { int t=a; a=b; b=t; } } class simple1 { public static void main(String as[]) { Swap ob=new Swap(); ob.set(10,20); System.out.println("…
Read moreclass sumdigit { public static void main(String as[]) { System.out.println("sum of digits program"); int n=12345; int d,sum=0; while(n>0) { d=n%10; n=n/10; sum=sum+d; } System.out.println("sum: "+sum); } } Output: sum of digits program sum: 15
Read moreclass displaydemo { public static void main(String args[]) { int n=1; int ln=1,l; char ch='*'; while(ln<=5) { for(l=1;l<=ln;l++) { System.out.print(ch+" "); } System.out.println(); ln++; } while(ln>0) { for(l=1;l<=ln;l++) { System.out.print(ch+&qu…
Read moresource file name: table.java class table { public static void main(String as[]) { System.out.println("table program"); int tn=5; for(int n=1;n<=10;n++) { System.out.println(tn*n); } } } Output: To compile this code use below command >javac table.java To run this code use …
Read moreclass sqcube { public static void main(String as[]) { System.out.println("square and cube program"); int n=5; int sq,c; sq=n*n; c=n*n*n; System.out.println("square "+sq+ " cube "+c); } } Output: To compile this code use below command D:\JavaPrograms\SimpleProgra…
Read more1) Write a Java program that finds and display addition, subtraction , multiplication and division of two numbers.
class simple1 { public static void main(String ad[]) { int a,b,add,sub,mul,div; a=100;b=50; System.out.println("static type input values are:"+a+","+b); add=a+b; sub=a-b; mul=a*b; div=a/b; System.out.println("addition value is:"+add); System.out.println("subst…
Read more