SlideShare ist ein Scribd-Unternehmen logo
1 von 71
1 
1. WAP to print following series: 
1 2 3 4 5 
1 2 3 4 
1 2 3 
1 2 
1 
class Serie1 
{ 
public static void main(String args[]) 
{ 
for(int i=5;i>=1;i--) 
{ 
for(int j=1;j<=i;j++) 
{ 
System.out.print(j); 
} 
System.out.println("n"); 
} 
} 
}
2 
Output:
3 
2. WAP to print following series: 
1 2 3 4 5 
2 3 4 5 
3 4 5 
4 5 
5 
class Serie2 
{ 
public static void main(String args[]) 
{ 
for(int i=1;i<=5;i++) 
{ 
for(int j=i;j<=5;j++) 
{ 
System.out.print(j); 
} 
System.out.println("n"); 
} 
} 
}
4 
Output:
5 
3. WAP to print following series: 
1 
1 2 
2 3 4 
4 5 6 7 
7 8 9 10 11 
class Serie3 
{ 
public static void main(String args[]) 
{ 
int n=1; 
for(int i=1;i<=5;i++) 
{ 
for(int j=1;j<=i;j++) 
{ 
System.out.print(n); 
n++; 
} 
System.out.println("n"); 
n--; 
} 
}
6 
} 
Output:
4.WAP to illustrate the use of io package to receive input for different datatypes. 
7 
import java.io.*; 
class Testio 
{ 
public static void main(String args[]) throws IOException 
{ 
BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); 
System.out.println("enter int value"); 
String s=br.readLine(); 
int i=Integer.parseInt(s); 
System.out.println("enter short value"); 
String a=br.readLine(); 
short sh=Short.parseShort(a); 
System.out.println("enter long value"); 
String x=br.readLine(); 
long l=Long.parseLong(x); 
System.out.println("enter float value"); 
String y=br.readLine(); 
float f=Float.parseFloat(y); 
System.out.println("enter double value"); 
String n=br.readLine(); 
double d=Double.parseDouble(n); 
System.out.println("enter string value");
8 
String z=br.readLine(); 
String st=z; 
System.out.println("enter boolean value"); 
String t=br.readLine(); 
boolean b=Boolean.parseBoolean(t); 
System.out.println("int i ="+i); 
System.out.println("short sh ="+sh); 
System.out.println("long l ="+l); 
System.out.println("float f ="+f); 
System.out.println("double d ="+d); 
System.out.println("String st ="+st); 
System.out.println("boolean b ="+b); 
} 
}
9 
Output:
5.WAP to illustrate the use of StringTokenizer class of util package. 
10 
import java.io.*; 
import java.util.*; 
class Testst 
{ 
public static void main(String args[]) throws IOException 
{ 
BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); 
System.out.println("enter Name,Age,Salary"); 
String str=br.readLine(); 
StringTokenizer st=new StringTokenizer(str,","); 
String s1=st.nextToken(); 
String s2=st.nextToken(); 
String s3=st.nextToken(); 
String name=s1; 
int age=Integer.parseInt(s2); 
float sal=Float.parseFloat(s3); 
System.out.println("Name = "+name); 
System.out.println("Age = "+age); 
System.out.println("Salary = "+sal); 
} 
}
11 
Output:
6.WAP to illustrate the use of Scanner class. 
12 
import java.util.Scanner; 
class Testscanner 
{ 
public static void main(String args[]) 
{ 
int a; 
float b; 
String c; 
Scanner ob=new Scanner(System.in); 
System.out.print("Enter an int : "); 
a=ob.nextInt(); 
System.out.print("Enter a float : "); 
b=ob.nextFloat(); 
System.out.print("Enter a string : "); 
c=ob.next(); 
System.out.println("a="+a); 
System.out.println("b="+b); 
System.out.println("c="+c); 
} 
}
13 
Output:
7. WAP to receive two inputs from user of different data types at same time and print it 
using Scanner class. 
14 
import java.util.Scanner; 
class Testms 
{ 
public static void main(String args[]) 
{ 
Scanner br=new Scanner(System.in); 
System.out.println("enter Name,Age"); 
String n=br.next(); 
int a=br.nextInt(); 
System.out.println("Name = "+n); 
System.out.println("Age = "+a); 
} 
} 
Output:
8. WAP to receive one number from user and print table of that number. 
15 
import java.util.Scanner; 
public class Table 
{ 
public static void main(String [] args) 
{ 
Scanner obj=new Scanner(System.in); 
System.out.print("enter any number : "); 
int n=obj.nextInt(); 
for(int j=1;j<=10;j++) 
{ 
System.out.print(n+"t"+"*"+"t"+j+"t"+"="+"t"+j*n); 
System.out.print("n"); 
} 
} 
} Output:
9. WAP to receive one number from user and print tables up to that number. 
16 
import java.util.Scanner; 
public class Table1 
{ 
public static void main(String [] args) 
{ 
Scanner obj=new Scanner(System.in); 
System.out.print("enter any number : "); 
int n=obj.nextInt(); 
for(int i=1;i<=n;i++) 
{ 
for(int j=1;j<=n;j++) 
{ 
System.out.print(i+"*"+j+"="+j*i); 
System.out.print("n"); 
} 
} 
} 
}
17 
Output:
10. WAP to except three numbers from the user and print largest among them using if 
else if statement. 
18 
import java.util.Scanner; 
public class Largest 
{ 
public static void main(String [] args) 
{ 
Scanner obj=new Scanner(System.in); 
System.out.print("enter 1st number : "); 
int a=obj.nextInt(); 
System.out.print("enter 2nd number : "); 
int b=obj.nextInt(); 
System.out.print("enter 3rd number : "); 
int c=obj.nextInt(); 
if(a>b && a>c) 
System.out.print(a+" is greatest number "); 
else if(b>a && b>c) 
System.out.print(b+" is greatest number "); 
else 
System.out.print(c+" is greatest number "); 
} 
}
19 
Output:
11. WAP to except three numbers from the user and print largest among them using 
nested if statement. 
20 
import java.util.Scanner; 
public class Largestn 
{ 
public static void main(String [] args) 
{ 
Scanner obj=new Scanner(System.in); 
System.out.print("enter 1st number : "); 
int a=obj.nextInt(); 
System.out.print("enter 2nd number : "); 
int b=obj.nextInt(); 
System.out.print("enter 3rd number : "); 
int c=obj.nextInt(); 
if(a>b) 
{ 
if(a>c) 
{ 
System.out.print(a+" is greatest number "); 
} 
else 
{ 
System.out.print(c+" is greatest number ");
21 
} 
} 
if(b>a) 
{ 
if(b>c) 
{ 
System.out.print(b+" is greatest number "); 
} 
else 
{ 
System.out.print(c+" is greatest number "); 
} 
} 
} 
} 
Output:
12. WAP to except three numbers from the user and print largest among them using 
nested if statement. 
22 
import java.util.Scanner; 
public class Largestm 
{ 
public static void main(String [] args) 
{ 
Scanner obj=new Scanner(System.in); 
System.out.print("enter 1st number : "); 
int a=obj.nextInt(); 
System.out.print("enter 2nd number : "); 
int b=obj.nextInt(); 
System.out.print("enter 3rd number : "); 
int c=obj.nextInt(); 
if (a>b && a>c) 
{ 
System.out.println("largest number is "+a); 
} 
if(b>a && b>c) 
{ 
System.out.println("largest number is "+b); 
} 
if(c>a && c>b)
23 
{ 
System.out.println("largest number is "+c); 
} 
} 
} 
Output:
13. WAP to show the use of command line arguments. 
24 
class Democa 
{ 
public static void main(String args[]) 
{ 
for(int i=0;i<args.length;i++) 
{ 
System.out.println("args["+i+"]: "+args[i]); 
} 
} 
} 
Output:
14. WAP to illustrate the use of String class methods. 
25 
class Teststr 
{ 
public static void main(String args[]) 
{ 
String s = " HELLO WORLD "; 
String s2 = "HELLO"; 
int l=s.length(); 
System.out.println("lenth():"); 
System.out.println("lenth="+l); 
System.out.println("charAt():"); 
System.out.println(s.charAt(3)); 
System.out.println("trim():"); 
System.out.println(s.trim()); 
System.out.println("toLowerCase():"); 
System.out.println(s.toLowerCase()); 
System.out.println("substring():"); 
System.out.println(s.substring(3,9)); 
System.out.println("indexOf():"); 
System.out.println(s.indexOf("L")); 
System.out.println("equals():"); 
if(s2.equals("HELLO")) 
System.out.println("HELLO"); 
else 
System.out.println("donot match"); 
System.out.println("compareTo():"); 
int ans1,ans2,ans3;
26 
ans1=s2.compareTo("ANNU"); 
ans2=s2.compareTo("HELLO"); 
ans3=s2.compareTo("SIMAR"); 
System.out.println(ans1); 
System.out.println(ans2); 
System.out.println(ans3); 
} 
} 
Output:
15. WAP to shows the use of array of object in java. 
27 
import java.util.Scanner; 
class Student 
{ 
int r; 
int m[] = new int[5]; 
String n; 
Scanner o= new Scanner(System.in); 
void getdata() 
{ 
System.out.print("enter rollno: "); 
r=o.nextInt(); 
System.out.print("enter name: "); 
n=o.next(); 
System.out.println("enter marks in 5 subjects"); 
for(int i=0;i<5;i++) 
{ 
m[i]=o.nextInt(); 
} 
} 
void putdata() 
{ 
int sum=0; 
System.out.println("rollno: "+r); 
System.out.println("name: "+n); 
System.out.println("list of marks");
28 
for(int i=0;i<5;i++) 
{ 
System.out.println("marks in sub"+(i+1)+" :"+m[i]); 
sum=sum+m[i]; 
} 
int per=((sum*100)/500); 
if(per<40) 
{ 
System.out.println("sorry! you are fail"); 
} 
else if(per>40 && per<=60) 
{ 
System.out.println("Division: Third"); 
} 
else if(per>60 && per<=80) 
{ 
System.out.println("Division: second"); 
} 
else if(per>80 && per<=100) 
{ 
System.out.println("Division: first"); 
} 
else if(per>100) 
{ 
System.out.println("invalid result"); 
} 
}
29 
} 
class T 
{ 
public static void main(String args[]) 
{ 
Student obj[]=new Student[2]; 
for(int i=0;i<2;i++) 
{ 
obj[i]=new Student(); 
obj[i].getdata(); 
} 
for(int i=0;i<2;i++) 
{ 
obj[i].putdata(); 
} 
} 
}
30 
Output:
16. WAP to enter the size of row and column for two dimension array, accept values from 
the user accordingly and print them along with column wise total. 
31 
import java.util.Scanner; 
class Carray 
{ 
public static void main(String args[]) 
{ 
int r,c; 
Scanner obj = new Scanner(System.in); 
System.out.println("enter size of row"); 
r=obj.nextInt(); 
System.out.println("enter size of column"); 
c=obj.nextInt(); 
int a[][]=new int[r][c]; 
System.out.println("enter"+r*c+"values"); 
for(int i=0;i<r;i++) 
{ 
for(int j=0;j<c;j++) 
{ 
a[i][j]=obj.nextInt(); 
} 
} 
int s[]=new int[r];
32 
System.out.println("Matrix is:"); 
for(int i=0;i<r;i++) 
{ 
s[i]=0; 
for(int j=0;j<c;j++) 
{ 
System.out.print(a[i][j]+"t"); 
s[i]=s[i]+a[j][i]; 
} 
System.out.print("nn"); 
} 
System.out.println("Columnwise total:"); 
for(int i=0;i<r;i++) 
{ 
System.out.print(s[i]+"t"); 
} 
} 
}
33 
Output:
17. WAP to enter the size of row and column for two dimension array, accept values from 
the user accordingly and print them along with diagonal total. 
34 
import java.util.Scanner; 
class Diagnal 
{ 
public static void main(String args[]) 
{ 
int r,c; 
Scanner obj = new Scanner(System.in); 
System.out.println("enter size of row"); 
r=obj.nextInt(); 
System.out.println("enter size of column"); 
c=obj.nextInt(); 
int a[][]=new int[r][c]; 
System.out.println("enter"+r*c+"values"); 
for(int i=0;i<r;i++) 
{ 
for(int j=0;j<c;j++) 
{ 
a[i][j]=obj.nextInt(); 
} 
} 
System.out.println("Matrix is: ");
35 
int s=0; 
for(int i=0;i<r;i++) 
{ 
for(int j=0;j<c;j++) 
{ 
System.out.print(a[i][j]+"t"); 
if(i==j) 
s=s+a[i][j]; 
} 
System.out.print("n"); 
} 
System.out.println("Sum of diagnal: "+s); 
} 
}
36 
Output:
18. WAP to enter the size of row and column for two dimension array, accept values from 
the user accordingly and print them along with row wise total. 
37 
import java.util.Scanner; 
class Rarray 
{ 
public static void main(String args[]) 
{ 
int r,c; 
Scanner obj = new Scanner(System.in); 
System.out.println("enter size of row"); 
r=obj.nextInt(); 
System.out.println("enter size of column"); 
c=obj.nextInt(); 
int a[][]=new int[r][c]; 
System.out.println("enter"+r*c+"values"); 
for(int i=0;i<r;i++) 
{ 
for(int j=0;j<c;j++) 
{ 
a[i][j]=obj.nextInt(); 
} 
} 
System.out.println("Matrix is: ");
38 
for(int i=0;i<r;i++) 
{ 
int s=0; 
for(int j=0;j<c;j++) 
{ 
System.out.print(a[i][j]+"t"); 
s=a[i][j]+s; 
} 
System.out.print("="+s); 
System.out.print("n"); 
} 
} 
} 
Output:
39 
19. WAP to show the use of static variable. 
class Testn 
{ 
int n; 
static int count; 
void getdata(int x) 
{ 
n=x; 
count++; 
} 
void getcount() 
{ 
System.out.println("count: "+count); 
} 
} 
class Testd 
{ 
Test o1=new Test(); 
Test o2=new Test(); 
Test o3=new Test(); 
o1.getcount(); 
o2.getcount(); 
o3.getcount();
40 
o1.getdata(10); 
o2.getdata(20); 
o3.getdata(30); 
o1.getcount(); 
o2.getcount(); 
o3.getcount(); 
} 
Output:
41 
20. WAP to show the use of static method. 
class Mathoperation 
{ 
static int mul(int a,int b) 
{ 
return(a*b); 
} 
static int mul(int a,int b,int c) 
{ 
return(a*b*c); 
} 
} 
class Statictest 
{ 
public static void main(String args[]) 
{ 
int f1=Mathoperation.mul(10,20); 
int f2=Mathoperation.mul(10,20,4); 
System.out.println("1st multiplication = "+f1); 
System.out.println("2nd multiplication = "+f2); 
} 
}
42 
Output:
21. WAP to show the use of parameterized constructor. 
43 
class A 
{ 
int a; 
A(int a) 
{ 
this.a=a; 
System.out.println("This is a constructor of class A"); 
} 
} 
class B extends A 
{ 
int b,c; 
B(int a,int b,int c) 
{ 
super(a); 
this.b=b; 
this.c=c; 
System.out.println("This is a constructor of class B"); 
} 
void display() 
{ 
System.out.println("a="+a);
44 
System.out.println("b="+b); 
System.out.println("c="+c); 
} 
} 
class ParCons 
{ 
public static void main(String args[]) 
{ 
B obj=new B(10,20,30); 
obj.display(); 
} 
} 
Output:
22. WAP to show the use of default constructor. 
45 
class A 
{ 
A() 
{ 
System.out.println("This is a constructor of class A"); 
} 
} 
class B extends A 
{ 
B() 
{ 
super(); 
System.out.println("This is a constructor of class B"); 
} 
} 
class DefCons 
{ 
public static void main(String args[]) 
{ 
B obj=new B(); 
} 
}
46 
Output:
23. WAP to show the use of overriding method. 
47 
class One 
{ 
void show() 
{ 
System.out.println("I am method of class One"); 
} 
} 
class Two extends One 
{ 
void show() 
{ 
System.out.println("I am method of class Two"); 
} 
} 
class Testoverriding 
{ 
public static void main(String args[]) 
{ 
One o=new One(); 
Two t=new Two(); 
o.show(); 
t.show();
48 
} 
} 
Output:
24. WAP to show the use of method overloading. 
49 
class Mathoperation 
{ 
static int mul(int a,int b) 
{ 
return(a*b); 
} 
static int mul(int a,int b,int c) 
{ 
return(a*b*c); 
} 
static float mul(int a,float b) 
{ 
return(a*b); 
} 
} 
class Testoverloading 
{ 
public static void main(String args[]) 
{ 
int f1=Mathoperation.mul(10,20); 
int f2=Mathoperation.mul(10,20,4); 
float f3=Mathoperation.mul(10,20.4f);
50 
System.out.println("1st multiplication = "+f1); 
System.out.println("2nd multiplication = "+f2); 
System.out.println("3rd multiplication = "+f3); 
} 
} 
Output:
51 
25. WAP to show the use of final method. 
class One 
{ 
final void show() 
{ 
System.out.println("i am belong to class One"); 
} 
final void show(int a) 
{ 
System.out.println("i am variable of class one = "+a); 
} 
} 
class Two extends One 
{ 
void show1() 
{ 
System.out.println("i am belong to class Two"); 
} 
} 
class Testfinal 
{ 
public static void main(String args[]) 
{
52 
Two t1 = new Two(); 
t1.show1(); 
t1.show(); 
t1.show(10); 
} 
} 
Output:
53 
26. WAP to show the use of final variable. 
class One 
{ 
final int x=5; 
} 
class Two extends One 
{ 
void show() 
{ 
System.out.println("x = "+x); 
} 
} 
class Testfinalvar 
{ 
public static void main(String args[]) 
{ 
Two t1 = new Two(); 
t1.show(); 
} 
}
54 
Output:
55 
27. WAP to show the use of final class. 
class One 
{ 
void show() 
{ 
System.out.println("I am method of final class."); 
} 
} 
class Testfinalclass 
{ 
public static void main(String args[]) 
{ 
One t1 = new One(); 
t1.show(); 
} 
} 
Output:
28. WAP to show the use of abstract method. 
56 
abstract class Demo 
{ 
abstract public void calculate(int x); 
} 
class Second extends Demo 
{ 
public void calculate(int x) 
{ 
System.out.println("square of "+x+" is "+(x*x)); 
} 
} 
class Third extends Demo 
{ 
public void calculate(int x) 
{ 
System.out.println("cube of "+x+" is "+(x*x*x)); 
} 
} 
class Testdemo 
{ 
public static void main(String args[]) 
{
57 
Second s =new Second(); 
s.calculate(10); 
Third t =new Third(); 
t.calculate(10); 
Demo d; 
d=s; 
d.calculate(10); 
d=t; 
t.calculate(10); 
} 
} 
Output:
29. WAP to show the use of package in classes. 
58 
package mypack; 
import java.util.Scanner; 
public class Student 
{ 
String n; 
Scanner o=new Scanner(System.in); 
public void getname() 
{ System.out.println("enter name"); 
n=o.next(); 
} 
public void putname() 
{ 
System.out.println("Name = "+n); 
} 
} 
import java.util.Scanner; 
import mypack.*; 
class Test1 
{ 
Scanner o= new Scanner(System.in); 
int s[]= new int[3]; 
void getdata()
59 
{ 
System.out.println("enter the data in 3 subjects:"); 
for(int i=0;i<3;i++) 
{ 
s[i]=o.nextInt(); 
} 
} 
void putdata() 
{ 
int sum=0; 
System.out.println("marks in 3 subjects:"); 
for(int i=0;i<3;i++) 
{ 
System.out.println("s["+i+"]:"+s[i]); 
sum=sum+s[i]; 
} 
System.out.println("Total = "+sum); 
int per=(sum*100)/300; 
System.out.println("percentage = "+per); 
if(per>80) 
System.out.println("First"); 
else if(per<80 && per>60) 
System.out.println("Second");
60 
else if(per>50 && per<60) 
System.out.println("Third"); 
else 
System.out.println("Sorry!you are fail"); 
} 
} 
class My 
{ 
public static void main(String args[]) 
{ 
Student o1=new Student(); 
Test1 m=new Test1(); 
o1.getname(); 
o1.putname(); 
m.getdata(); 
m.putdata(); 
} 
}
61 
Output:
30. WAP to demonstrate the use of interface which contains two methods one can accept 
the input and second for displaying input. 
62 
interface One 
{ 
void getdata(int x,int y); 
void display(); 
} 
class Super implements One 
{ 
int a,b; 
public void getdata(int x,int y) 
{ 
a=x; 
b=y; 
} 
public void display() 
{ 
System.out.println("a = "+a); 
System.out.println("b = "+b); 
} 
} 
class Testinterface 
{
63 
public static void main(String args[]) 
{ 
Super s=new Super(); 
One o; 
o=s; 
o.getdata(10,20); 
o.display(); 
} 
} 
Output:
31. WAP in which you can implement an interface which contain one method and 
variable. 
64 
interface Area 
{ 
float pi=3.14f; 
float compute(float x,float y); 
} 
class Rectangle implements Area 
{ 
public float compute(float x, float y) 
{ 
return(x*y); 
} 
} 
class Circle implements Area 
{ 
public float compute(float x,float y) 
{ 
return(pi*x*x); 
} 
} 
class Interfacetest 
{
65 
public static void main(String args[]) 
{ 
Rectangle r=new Rectangle(); 
Circle c=new Circle(); 
System.out.println("Area of rectangle = " + r.compute(10.1f,20.2f)); 
System.out.println("Area of circle = " + c.compute(10.0f,0)); 
} 
} 
Output:
32. WAP to show the use of predefined exception. 
66 
class Testpre 
{ 
public static void main(String args[]) 
{ 
try 
{ 
int n = args.length; 
int a = 45 / n; 
System.out.println("The value of a is :"+a); 
} 
catch(ArithmeticException ae) 
{ 
System.out.println(ae); 
System.out.println("Arguments are required"); 
} 
finally 
{ 
System.out.println("End of program"); 
} 
} 
}
67 
Output:
33. WAP to show the use of user defined exception. 
68 
import java.util.Scanner; 
class MyException2 extends Exception 
{ 
static Scanner o=new Scanner(System.in); 
static int a[] =new int[5]; 
MyException2(String str) 
{ 
super(str); 
} 
public static void main(String args[]) 
{ 
try 
{ 
System.out.println("enter 5 numbers"); 
for(int i=0;i<5;i++) 
{ 
a[i]=o.nextInt(); 
if(a[i]>0) 
System.out.println("a["+i+"] : "+a[i]); 
else 
{ 
MyException2 me= new MyException2("enter positive number");
69 
throw me; 
} 
} 
} 
catch(MyException2 me) 
{ 
me.printStackTrace(); 
} 
} 
} 
Output:
70 
34. WAP to show the use of multi threading. 
class Mythread implements Runnable 
{ 
String str; 
Mythread(String str) 
{ 
this.str = str; 
} 
public void run() 
{ 
for(int i=1; i<=10; i++) 
{ 
System.out.println(str+i); 
try 
{ 
Thread.sleep(2000); 
} 
catch (InterruptedException ie) 
{ 
ie.printStackTrace(); 
} 
} 
}
71 
} 
class Theatre 
{ 
public static void main(String args[]) 
{ 
Mythread obj1 = new Mythread("Cut the ticket"); 
Mythread obj2 = new Mythread("Show the seat"); 
Thread t1 = new Thread(obj1); 
Thread t2 = new Thread(obj2); 
t1.start(); 
t2.start(); 
} 
} 
Output:

Weitere ähnliche Inhalte

Was ist angesagt?

Java_practical_handbook
Java_practical_handbookJava_practical_handbook
Java_practical_handbookManusha Dilan
 
16. Java stacks and queues
16. Java stacks and queues16. Java stacks and queues
16. Java stacks and queuesIntro C# Book
 
Computer java programs
Computer java programsComputer java programs
Computer java programsADITYA BHARTI
 
Python 2.5 reference card (2009)
Python 2.5 reference card (2009)Python 2.5 reference card (2009)
Python 2.5 reference card (2009)gekiaruj
 
Presentation1 computer shaan
Presentation1 computer shaanPresentation1 computer shaan
Presentation1 computer shaanwalia Shaan
 
07. Java Array, Set and Maps
07.  Java Array, Set and Maps07.  Java Array, Set and Maps
07. Java Array, Set and MapsIntro C# Book
 
The Ring programming language version 1.6 book - Part 183 of 189
The Ring programming language version 1.6 book - Part 183 of 189The Ring programming language version 1.6 book - Part 183 of 189
The Ring programming language version 1.6 book - Part 183 of 189Mahmoud Samir Fayed
 
JDays 2016 - Beyond Lambdas - the Aftermath
JDays 2016 - Beyond Lambdas - the AftermathJDays 2016 - Beyond Lambdas - the Aftermath
JDays 2016 - Beyond Lambdas - the AftermathDaniel Sawano
 
Java practice programs for beginners
Java practice programs for beginnersJava practice programs for beginners
Java practice programs for beginnersishan0019
 
Important java programs(collection+file)
Important java programs(collection+file)Important java programs(collection+file)
Important java programs(collection+file)Alok Kumar
 
Spotify 2016 - Beyond Lambdas - the Aftermath
Spotify 2016 - Beyond Lambdas - the AftermathSpotify 2016 - Beyond Lambdas - the Aftermath
Spotify 2016 - Beyond Lambdas - the AftermathDaniel Sawano
 
Java Simple Programs
Java Simple ProgramsJava Simple Programs
Java Simple ProgramsUpender Upr
 

Was ist angesagt? (18)

Java_practical_handbook
Java_practical_handbookJava_practical_handbook
Java_practical_handbook
 
16. Java stacks and queues
16. Java stacks and queues16. Java stacks and queues
16. Java stacks and queues
 
Computer java programs
Computer java programsComputer java programs
Computer java programs
 
DCN Practical
DCN PracticalDCN Practical
DCN Practical
 
Sam wd programs
Sam wd programsSam wd programs
Sam wd programs
 
Python 2.5 reference card (2009)
Python 2.5 reference card (2009)Python 2.5 reference card (2009)
Python 2.5 reference card (2009)
 
Java programs
Java programsJava programs
Java programs
 
Presentation1 computer shaan
Presentation1 computer shaanPresentation1 computer shaan
Presentation1 computer shaan
 
C#
C#C#
C#
 
Ann
AnnAnn
Ann
 
07. Java Array, Set and Maps
07.  Java Array, Set and Maps07.  Java Array, Set and Maps
07. Java Array, Set and Maps
 
Oop lecture9 13
Oop lecture9 13Oop lecture9 13
Oop lecture9 13
 
The Ring programming language version 1.6 book - Part 183 of 189
The Ring programming language version 1.6 book - Part 183 of 189The Ring programming language version 1.6 book - Part 183 of 189
The Ring programming language version 1.6 book - Part 183 of 189
 
JDays 2016 - Beyond Lambdas - the Aftermath
JDays 2016 - Beyond Lambdas - the AftermathJDays 2016 - Beyond Lambdas - the Aftermath
JDays 2016 - Beyond Lambdas - the Aftermath
 
Java practice programs for beginners
Java practice programs for beginnersJava practice programs for beginners
Java practice programs for beginners
 
Important java programs(collection+file)
Important java programs(collection+file)Important java programs(collection+file)
Important java programs(collection+file)
 
Spotify 2016 - Beyond Lambdas - the Aftermath
Spotify 2016 - Beyond Lambdas - the AftermathSpotify 2016 - Beyond Lambdas - the Aftermath
Spotify 2016 - Beyond Lambdas - the Aftermath
 
Java Simple Programs
Java Simple ProgramsJava Simple Programs
Java Simple Programs
 

Andere mochten auch

Questionnaire analysis - Music Videos
Questionnaire analysis - Music VideosQuestionnaire analysis - Music Videos
Questionnaire analysis - Music VideosCloee Lang
 
Approaches_for_planning_the_ISS_cosmonau
Approaches_for_planning_the_ISS_cosmonauApproaches_for_planning_the_ISS_cosmonau
Approaches_for_planning_the_ISS_cosmonauNail Khusnullin
 
Media Storyboard
Media StoryboardMedia Storyboard
Media StoryboardCloee Lang
 
Photoshop project tutorial
Photoshop project tutorialPhotoshop project tutorial
Photoshop project tutorialmeyrni-ahmed
 
Informe TTIP
Informe TTIPInforme TTIP
Informe TTIPmredondo6
 
Departments and its functions
Departments and its functionsDepartments and its functions
Departments and its functionsAshutosh Bhalerao
 
Music Magazine Analysis
Music Magazine AnalysisMusic Magazine Analysis
Music Magazine AnalysisCloee Lang
 
CoderDojo lightening talk
CoderDojo lightening talkCoderDojo lightening talk
CoderDojo lightening talkwillimus
 

Andere mochten auch (15)

Conventional representation
Conventional representationConventional representation
Conventional representation
 
Questionnaire analysis - Music Videos
Questionnaire analysis - Music VideosQuestionnaire analysis - Music Videos
Questionnaire analysis - Music Videos
 
Approaches_for_planning_the_ISS_cosmonau
Approaches_for_planning_the_ISS_cosmonauApproaches_for_planning_the_ISS_cosmonau
Approaches_for_planning_the_ISS_cosmonau
 
Doe process-development-validation
Doe process-development-validationDoe process-development-validation
Doe process-development-validation
 
Media Storyboard
Media StoryboardMedia Storyboard
Media Storyboard
 
Photoshop project tutorial
Photoshop project tutorialPhotoshop project tutorial
Photoshop project tutorial
 
Informe TTIP
Informe TTIPInforme TTIP
Informe TTIP
 
Step 1
Step 1Step 1
Step 1
 
tes
testes
tes
 
Excception handling
Excception handlingExcception handling
Excception handling
 
Departments and its functions
Departments and its functionsDepartments and its functions
Departments and its functions
 
Music Magazine Analysis
Music Magazine AnalysisMusic Magazine Analysis
Music Magazine Analysis
 
The Nicholson Award
The Nicholson AwardThe Nicholson Award
The Nicholson Award
 
CoderDojo lightening talk
CoderDojo lightening talkCoderDojo lightening talk
CoderDojo lightening talk
 
El punto
El puntoEl punto
El punto
 

Ähnlich wie Java file

Lab01.pptx
Lab01.pptxLab01.pptx
Lab01.pptxKimVeeL
 
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
 Problem1 java codeimport java.util.Scanner; Java code to pr.pdf Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
Problem1 java codeimport java.util.Scanner; Java code to pr.pdfanupamfootwear
 
JAVA PRACTICE QUESTIONS v1.4.pdf
JAVA PRACTICE QUESTIONS v1.4.pdfJAVA PRACTICE QUESTIONS v1.4.pdf
JAVA PRACTICE QUESTIONS v1.4.pdfRohitkumarYadav80
 
import java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdfimport java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdfoptokunal1
 
Lab101.pptx
Lab101.pptxLab101.pptx
Lab101.pptxKimVeeL
 
CODEimport java.util.; public class test { public static voi.pdf
CODEimport java.util.; public class test { public static voi.pdfCODEimport java.util.; public class test { public static voi.pdf
CODEimport java.util.; public class test { public static voi.pdfanurag1231
 
java program assigment -2
java program assigment -2java program assigment -2
java program assigment -2Ankit Gupta
 
import java.uti-WPS Office.docx
import java.uti-WPS Office.docximport java.uti-WPS Office.docx
import java.uti-WPS Office.docxKatecate1
 
Star pattern programs in java Print Star pattern in java and print triangle ...
Star pattern programs in java Print Star pattern in java and  print triangle ...Star pattern programs in java Print Star pattern in java and  print triangle ...
Star pattern programs in java Print Star pattern in java and print triangle ...Hiraniahmad
 
KOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian KomputerKOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian KomputerAiman Hud
 

Ähnlich wie Java file (20)

Lab01.pptx
Lab01.pptxLab01.pptx
Lab01.pptx
 
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
 Problem1 java codeimport java.util.Scanner; Java code to pr.pdf Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
 
JAVA PRACTICE QUESTIONS v1.4.pdf
JAVA PRACTICE QUESTIONS v1.4.pdfJAVA PRACTICE QUESTIONS v1.4.pdf
JAVA PRACTICE QUESTIONS v1.4.pdf
 
import java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdfimport java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdf
 
Lab101.pptx
Lab101.pptxLab101.pptx
Lab101.pptx
 
JAVA.pdf
JAVA.pdfJAVA.pdf
JAVA.pdf
 
Java programs
Java programsJava programs
Java programs
 
The Art of Clean Code
The Art of Clean CodeThe Art of Clean Code
The Art of Clean Code
 
Oot practical
Oot practicalOot practical
Oot practical
 
CODEimport java.util.; public class test { public static voi.pdf
CODEimport java.util.; public class test { public static voi.pdfCODEimport java.util.; public class test { public static voi.pdf
CODEimport java.util.; public class test { public static voi.pdf
 
java program assigment -2
java program assigment -2java program assigment -2
java program assigment -2
 
import java.uti-WPS Office.docx
import java.uti-WPS Office.docximport java.uti-WPS Office.docx
import java.uti-WPS Office.docx
 
.net progrmming part2
.net progrmming part2.net progrmming part2
.net progrmming part2
 
3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.pdf3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.pdf
 
Java practical
Java practicalJava practical
Java practical
 
Star pattern programs in java Print Star pattern in java and print triangle ...
Star pattern programs in java Print Star pattern in java and  print triangle ...Star pattern programs in java Print Star pattern in java and  print triangle ...
Star pattern programs in java Print Star pattern in java and print triangle ...
 
KOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian KomputerKOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
 
Java Unit 1 Project
Java Unit 1 ProjectJava Unit 1 Project
Java Unit 1 Project
 
Computer programming 2 chapter 1-lesson 2
Computer programming 2  chapter 1-lesson 2Computer programming 2  chapter 1-lesson 2
Computer programming 2 chapter 1-lesson 2
 
WAP to add two given matrices in Java
WAP to add two given matrices in JavaWAP to add two given matrices in Java
WAP to add two given matrices in Java
 

Mehr von simarsimmygrewal (8)

Java file
Java fileJava file
Java file
 
C file
C fileC file
C file
 
C file
C fileC file
C file
 
C++ file
C++ fileC++ file
C++ file
 
Handling inputs via scanner class
Handling inputs via scanner classHandling inputs via scanner class
Handling inputs via scanner class
 
Handling inputs via io..continue
Handling inputs via io..continueHandling inputs via io..continue
Handling inputs via io..continue
 
Type casting
Type castingType casting
Type casting
 
Wrapper classes
Wrapper classesWrapper classes
Wrapper classes
 

Kürzlich hochgeladen

TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 

Kürzlich hochgeladen (20)

TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 

Java file

  • 1. 1 1. WAP to print following series: 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1 class Serie1 { public static void main(String args[]) { for(int i=5;i>=1;i--) { for(int j=1;j<=i;j++) { System.out.print(j); } System.out.println("n"); } } }
  • 3. 3 2. WAP to print following series: 1 2 3 4 5 2 3 4 5 3 4 5 4 5 5 class Serie2 { public static void main(String args[]) { for(int i=1;i<=5;i++) { for(int j=i;j<=5;j++) { System.out.print(j); } System.out.println("n"); } } }
  • 5. 5 3. WAP to print following series: 1 1 2 2 3 4 4 5 6 7 7 8 9 10 11 class Serie3 { public static void main(String args[]) { int n=1; for(int i=1;i<=5;i++) { for(int j=1;j<=i;j++) { System.out.print(n); n++; } System.out.println("n"); n--; } }
  • 7. 4.WAP to illustrate the use of io package to receive input for different datatypes. 7 import java.io.*; class Testio { public static void main(String args[]) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("enter int value"); String s=br.readLine(); int i=Integer.parseInt(s); System.out.println("enter short value"); String a=br.readLine(); short sh=Short.parseShort(a); System.out.println("enter long value"); String x=br.readLine(); long l=Long.parseLong(x); System.out.println("enter float value"); String y=br.readLine(); float f=Float.parseFloat(y); System.out.println("enter double value"); String n=br.readLine(); double d=Double.parseDouble(n); System.out.println("enter string value");
  • 8. 8 String z=br.readLine(); String st=z; System.out.println("enter boolean value"); String t=br.readLine(); boolean b=Boolean.parseBoolean(t); System.out.println("int i ="+i); System.out.println("short sh ="+sh); System.out.println("long l ="+l); System.out.println("float f ="+f); System.out.println("double d ="+d); System.out.println("String st ="+st); System.out.println("boolean b ="+b); } }
  • 10. 5.WAP to illustrate the use of StringTokenizer class of util package. 10 import java.io.*; import java.util.*; class Testst { public static void main(String args[]) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("enter Name,Age,Salary"); String str=br.readLine(); StringTokenizer st=new StringTokenizer(str,","); String s1=st.nextToken(); String s2=st.nextToken(); String s3=st.nextToken(); String name=s1; int age=Integer.parseInt(s2); float sal=Float.parseFloat(s3); System.out.println("Name = "+name); System.out.println("Age = "+age); System.out.println("Salary = "+sal); } }
  • 12. 6.WAP to illustrate the use of Scanner class. 12 import java.util.Scanner; class Testscanner { public static void main(String args[]) { int a; float b; String c; Scanner ob=new Scanner(System.in); System.out.print("Enter an int : "); a=ob.nextInt(); System.out.print("Enter a float : "); b=ob.nextFloat(); System.out.print("Enter a string : "); c=ob.next(); System.out.println("a="+a); System.out.println("b="+b); System.out.println("c="+c); } }
  • 14. 7. WAP to receive two inputs from user of different data types at same time and print it using Scanner class. 14 import java.util.Scanner; class Testms { public static void main(String args[]) { Scanner br=new Scanner(System.in); System.out.println("enter Name,Age"); String n=br.next(); int a=br.nextInt(); System.out.println("Name = "+n); System.out.println("Age = "+a); } } Output:
  • 15. 8. WAP to receive one number from user and print table of that number. 15 import java.util.Scanner; public class Table { public static void main(String [] args) { Scanner obj=new Scanner(System.in); System.out.print("enter any number : "); int n=obj.nextInt(); for(int j=1;j<=10;j++) { System.out.print(n+"t"+"*"+"t"+j+"t"+"="+"t"+j*n); System.out.print("n"); } } } Output:
  • 16. 9. WAP to receive one number from user and print tables up to that number. 16 import java.util.Scanner; public class Table1 { public static void main(String [] args) { Scanner obj=new Scanner(System.in); System.out.print("enter any number : "); int n=obj.nextInt(); for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { System.out.print(i+"*"+j+"="+j*i); System.out.print("n"); } } } }
  • 18. 10. WAP to except three numbers from the user and print largest among them using if else if statement. 18 import java.util.Scanner; public class Largest { public static void main(String [] args) { Scanner obj=new Scanner(System.in); System.out.print("enter 1st number : "); int a=obj.nextInt(); System.out.print("enter 2nd number : "); int b=obj.nextInt(); System.out.print("enter 3rd number : "); int c=obj.nextInt(); if(a>b && a>c) System.out.print(a+" is greatest number "); else if(b>a && b>c) System.out.print(b+" is greatest number "); else System.out.print(c+" is greatest number "); } }
  • 20. 11. WAP to except three numbers from the user and print largest among them using nested if statement. 20 import java.util.Scanner; public class Largestn { public static void main(String [] args) { Scanner obj=new Scanner(System.in); System.out.print("enter 1st number : "); int a=obj.nextInt(); System.out.print("enter 2nd number : "); int b=obj.nextInt(); System.out.print("enter 3rd number : "); int c=obj.nextInt(); if(a>b) { if(a>c) { System.out.print(a+" is greatest number "); } else { System.out.print(c+" is greatest number ");
  • 21. 21 } } if(b>a) { if(b>c) { System.out.print(b+" is greatest number "); } else { System.out.print(c+" is greatest number "); } } } } Output:
  • 22. 12. WAP to except three numbers from the user and print largest among them using nested if statement. 22 import java.util.Scanner; public class Largestm { public static void main(String [] args) { Scanner obj=new Scanner(System.in); System.out.print("enter 1st number : "); int a=obj.nextInt(); System.out.print("enter 2nd number : "); int b=obj.nextInt(); System.out.print("enter 3rd number : "); int c=obj.nextInt(); if (a>b && a>c) { System.out.println("largest number is "+a); } if(b>a && b>c) { System.out.println("largest number is "+b); } if(c>a && c>b)
  • 23. 23 { System.out.println("largest number is "+c); } } } Output:
  • 24. 13. WAP to show the use of command line arguments. 24 class Democa { public static void main(String args[]) { for(int i=0;i<args.length;i++) { System.out.println("args["+i+"]: "+args[i]); } } } Output:
  • 25. 14. WAP to illustrate the use of String class methods. 25 class Teststr { public static void main(String args[]) { String s = " HELLO WORLD "; String s2 = "HELLO"; int l=s.length(); System.out.println("lenth():"); System.out.println("lenth="+l); System.out.println("charAt():"); System.out.println(s.charAt(3)); System.out.println("trim():"); System.out.println(s.trim()); System.out.println("toLowerCase():"); System.out.println(s.toLowerCase()); System.out.println("substring():"); System.out.println(s.substring(3,9)); System.out.println("indexOf():"); System.out.println(s.indexOf("L")); System.out.println("equals():"); if(s2.equals("HELLO")) System.out.println("HELLO"); else System.out.println("donot match"); System.out.println("compareTo():"); int ans1,ans2,ans3;
  • 26. 26 ans1=s2.compareTo("ANNU"); ans2=s2.compareTo("HELLO"); ans3=s2.compareTo("SIMAR"); System.out.println(ans1); System.out.println(ans2); System.out.println(ans3); } } Output:
  • 27. 15. WAP to shows the use of array of object in java. 27 import java.util.Scanner; class Student { int r; int m[] = new int[5]; String n; Scanner o= new Scanner(System.in); void getdata() { System.out.print("enter rollno: "); r=o.nextInt(); System.out.print("enter name: "); n=o.next(); System.out.println("enter marks in 5 subjects"); for(int i=0;i<5;i++) { m[i]=o.nextInt(); } } void putdata() { int sum=0; System.out.println("rollno: "+r); System.out.println("name: "+n); System.out.println("list of marks");
  • 28. 28 for(int i=0;i<5;i++) { System.out.println("marks in sub"+(i+1)+" :"+m[i]); sum=sum+m[i]; } int per=((sum*100)/500); if(per<40) { System.out.println("sorry! you are fail"); } else if(per>40 && per<=60) { System.out.println("Division: Third"); } else if(per>60 && per<=80) { System.out.println("Division: second"); } else if(per>80 && per<=100) { System.out.println("Division: first"); } else if(per>100) { System.out.println("invalid result"); } }
  • 29. 29 } class T { public static void main(String args[]) { Student obj[]=new Student[2]; for(int i=0;i<2;i++) { obj[i]=new Student(); obj[i].getdata(); } for(int i=0;i<2;i++) { obj[i].putdata(); } } }
  • 31. 16. WAP to enter the size of row and column for two dimension array, accept values from the user accordingly and print them along with column wise total. 31 import java.util.Scanner; class Carray { public static void main(String args[]) { int r,c; Scanner obj = new Scanner(System.in); System.out.println("enter size of row"); r=obj.nextInt(); System.out.println("enter size of column"); c=obj.nextInt(); int a[][]=new int[r][c]; System.out.println("enter"+r*c+"values"); for(int i=0;i<r;i++) { for(int j=0;j<c;j++) { a[i][j]=obj.nextInt(); } } int s[]=new int[r];
  • 32. 32 System.out.println("Matrix is:"); for(int i=0;i<r;i++) { s[i]=0; for(int j=0;j<c;j++) { System.out.print(a[i][j]+"t"); s[i]=s[i]+a[j][i]; } System.out.print("nn"); } System.out.println("Columnwise total:"); for(int i=0;i<r;i++) { System.out.print(s[i]+"t"); } } }
  • 34. 17. WAP to enter the size of row and column for two dimension array, accept values from the user accordingly and print them along with diagonal total. 34 import java.util.Scanner; class Diagnal { public static void main(String args[]) { int r,c; Scanner obj = new Scanner(System.in); System.out.println("enter size of row"); r=obj.nextInt(); System.out.println("enter size of column"); c=obj.nextInt(); int a[][]=new int[r][c]; System.out.println("enter"+r*c+"values"); for(int i=0;i<r;i++) { for(int j=0;j<c;j++) { a[i][j]=obj.nextInt(); } } System.out.println("Matrix is: ");
  • 35. 35 int s=0; for(int i=0;i<r;i++) { for(int j=0;j<c;j++) { System.out.print(a[i][j]+"t"); if(i==j) s=s+a[i][j]; } System.out.print("n"); } System.out.println("Sum of diagnal: "+s); } }
  • 37. 18. WAP to enter the size of row and column for two dimension array, accept values from the user accordingly and print them along with row wise total. 37 import java.util.Scanner; class Rarray { public static void main(String args[]) { int r,c; Scanner obj = new Scanner(System.in); System.out.println("enter size of row"); r=obj.nextInt(); System.out.println("enter size of column"); c=obj.nextInt(); int a[][]=new int[r][c]; System.out.println("enter"+r*c+"values"); for(int i=0;i<r;i++) { for(int j=0;j<c;j++) { a[i][j]=obj.nextInt(); } } System.out.println("Matrix is: ");
  • 38. 38 for(int i=0;i<r;i++) { int s=0; for(int j=0;j<c;j++) { System.out.print(a[i][j]+"t"); s=a[i][j]+s; } System.out.print("="+s); System.out.print("n"); } } } Output:
  • 39. 39 19. WAP to show the use of static variable. class Testn { int n; static int count; void getdata(int x) { n=x; count++; } void getcount() { System.out.println("count: "+count); } } class Testd { Test o1=new Test(); Test o2=new Test(); Test o3=new Test(); o1.getcount(); o2.getcount(); o3.getcount();
  • 40. 40 o1.getdata(10); o2.getdata(20); o3.getdata(30); o1.getcount(); o2.getcount(); o3.getcount(); } Output:
  • 41. 41 20. WAP to show the use of static method. class Mathoperation { static int mul(int a,int b) { return(a*b); } static int mul(int a,int b,int c) { return(a*b*c); } } class Statictest { public static void main(String args[]) { int f1=Mathoperation.mul(10,20); int f2=Mathoperation.mul(10,20,4); System.out.println("1st multiplication = "+f1); System.out.println("2nd multiplication = "+f2); } }
  • 43. 21. WAP to show the use of parameterized constructor. 43 class A { int a; A(int a) { this.a=a; System.out.println("This is a constructor of class A"); } } class B extends A { int b,c; B(int a,int b,int c) { super(a); this.b=b; this.c=c; System.out.println("This is a constructor of class B"); } void display() { System.out.println("a="+a);
  • 44. 44 System.out.println("b="+b); System.out.println("c="+c); } } class ParCons { public static void main(String args[]) { B obj=new B(10,20,30); obj.display(); } } Output:
  • 45. 22. WAP to show the use of default constructor. 45 class A { A() { System.out.println("This is a constructor of class A"); } } class B extends A { B() { super(); System.out.println("This is a constructor of class B"); } } class DefCons { public static void main(String args[]) { B obj=new B(); } }
  • 47. 23. WAP to show the use of overriding method. 47 class One { void show() { System.out.println("I am method of class One"); } } class Two extends One { void show() { System.out.println("I am method of class Two"); } } class Testoverriding { public static void main(String args[]) { One o=new One(); Two t=new Two(); o.show(); t.show();
  • 48. 48 } } Output:
  • 49. 24. WAP to show the use of method overloading. 49 class Mathoperation { static int mul(int a,int b) { return(a*b); } static int mul(int a,int b,int c) { return(a*b*c); } static float mul(int a,float b) { return(a*b); } } class Testoverloading { public static void main(String args[]) { int f1=Mathoperation.mul(10,20); int f2=Mathoperation.mul(10,20,4); float f3=Mathoperation.mul(10,20.4f);
  • 50. 50 System.out.println("1st multiplication = "+f1); System.out.println("2nd multiplication = "+f2); System.out.println("3rd multiplication = "+f3); } } Output:
  • 51. 51 25. WAP to show the use of final method. class One { final void show() { System.out.println("i am belong to class One"); } final void show(int a) { System.out.println("i am variable of class one = "+a); } } class Two extends One { void show1() { System.out.println("i am belong to class Two"); } } class Testfinal { public static void main(String args[]) {
  • 52. 52 Two t1 = new Two(); t1.show1(); t1.show(); t1.show(10); } } Output:
  • 53. 53 26. WAP to show the use of final variable. class One { final int x=5; } class Two extends One { void show() { System.out.println("x = "+x); } } class Testfinalvar { public static void main(String args[]) { Two t1 = new Two(); t1.show(); } }
  • 55. 55 27. WAP to show the use of final class. class One { void show() { System.out.println("I am method of final class."); } } class Testfinalclass { public static void main(String args[]) { One t1 = new One(); t1.show(); } } Output:
  • 56. 28. WAP to show the use of abstract method. 56 abstract class Demo { abstract public void calculate(int x); } class Second extends Demo { public void calculate(int x) { System.out.println("square of "+x+" is "+(x*x)); } } class Third extends Demo { public void calculate(int x) { System.out.println("cube of "+x+" is "+(x*x*x)); } } class Testdemo { public static void main(String args[]) {
  • 57. 57 Second s =new Second(); s.calculate(10); Third t =new Third(); t.calculate(10); Demo d; d=s; d.calculate(10); d=t; t.calculate(10); } } Output:
  • 58. 29. WAP to show the use of package in classes. 58 package mypack; import java.util.Scanner; public class Student { String n; Scanner o=new Scanner(System.in); public void getname() { System.out.println("enter name"); n=o.next(); } public void putname() { System.out.println("Name = "+n); } } import java.util.Scanner; import mypack.*; class Test1 { Scanner o= new Scanner(System.in); int s[]= new int[3]; void getdata()
  • 59. 59 { System.out.println("enter the data in 3 subjects:"); for(int i=0;i<3;i++) { s[i]=o.nextInt(); } } void putdata() { int sum=0; System.out.println("marks in 3 subjects:"); for(int i=0;i<3;i++) { System.out.println("s["+i+"]:"+s[i]); sum=sum+s[i]; } System.out.println("Total = "+sum); int per=(sum*100)/300; System.out.println("percentage = "+per); if(per>80) System.out.println("First"); else if(per<80 && per>60) System.out.println("Second");
  • 60. 60 else if(per>50 && per<60) System.out.println("Third"); else System.out.println("Sorry!you are fail"); } } class My { public static void main(String args[]) { Student o1=new Student(); Test1 m=new Test1(); o1.getname(); o1.putname(); m.getdata(); m.putdata(); } }
  • 62. 30. WAP to demonstrate the use of interface which contains two methods one can accept the input and second for displaying input. 62 interface One { void getdata(int x,int y); void display(); } class Super implements One { int a,b; public void getdata(int x,int y) { a=x; b=y; } public void display() { System.out.println("a = "+a); System.out.println("b = "+b); } } class Testinterface {
  • 63. 63 public static void main(String args[]) { Super s=new Super(); One o; o=s; o.getdata(10,20); o.display(); } } Output:
  • 64. 31. WAP in which you can implement an interface which contain one method and variable. 64 interface Area { float pi=3.14f; float compute(float x,float y); } class Rectangle implements Area { public float compute(float x, float y) { return(x*y); } } class Circle implements Area { public float compute(float x,float y) { return(pi*x*x); } } class Interfacetest {
  • 65. 65 public static void main(String args[]) { Rectangle r=new Rectangle(); Circle c=new Circle(); System.out.println("Area of rectangle = " + r.compute(10.1f,20.2f)); System.out.println("Area of circle = " + c.compute(10.0f,0)); } } Output:
  • 66. 32. WAP to show the use of predefined exception. 66 class Testpre { public static void main(String args[]) { try { int n = args.length; int a = 45 / n; System.out.println("The value of a is :"+a); } catch(ArithmeticException ae) { System.out.println(ae); System.out.println("Arguments are required"); } finally { System.out.println("End of program"); } } }
  • 68. 33. WAP to show the use of user defined exception. 68 import java.util.Scanner; class MyException2 extends Exception { static Scanner o=new Scanner(System.in); static int a[] =new int[5]; MyException2(String str) { super(str); } public static void main(String args[]) { try { System.out.println("enter 5 numbers"); for(int i=0;i<5;i++) { a[i]=o.nextInt(); if(a[i]>0) System.out.println("a["+i+"] : "+a[i]); else { MyException2 me= new MyException2("enter positive number");
  • 69. 69 throw me; } } } catch(MyException2 me) { me.printStackTrace(); } } } Output:
  • 70. 70 34. WAP to show the use of multi threading. class Mythread implements Runnable { String str; Mythread(String str) { this.str = str; } public void run() { for(int i=1; i<=10; i++) { System.out.println(str+i); try { Thread.sleep(2000); } catch (InterruptedException ie) { ie.printStackTrace(); } } }
  • 71. 71 } class Theatre { public static void main(String args[]) { Mythread obj1 = new Mythread("Cut the ticket"); Mythread obj2 = new Mythread("Show the seat"); Thread t1 = new Thread(obj1); Thread t2 = new Thread(obj2); t1.start(); t2.start(); } } Output: