Tag: 3rd sem JAVA
JAVA 2018 Old Paper Solutions
 Year 2018 Q.no 11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
import java.util.Scanner; public class matrix { public static void main(String args[]){ int i,j = 0,s=0; int a[][]=new int[2][3]; Scanner sc=new Scanner(System.in); System.out.println("enter the elements in matrix"); for(i=0;i<2;i++){ for(j=0;j<3;j++){ a[i][j]=sc.nextInt(); s=s+a[i][j]; } } System.out.println("sum="+s); } } |
Q.no 13
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
import java.util.*; import java.lang.*; abstract class Y2018q13 { abstract void putdata(String b, int a, int c); abstract void getdata(); } class Airplane extends Y2018q13 { int code; String name; int capacity; void putdata(String b, int a, int c) { code = a; name = b; capacity = c; } void getdata() { System.out.println("code=" + code + " name=" + name + " Capacity=" + capacity); } } class Apply { public static void main(String args[]) { Scanner sc = new Scanner(System.in); Airplane ab = new Airplane(); System.out.println("Enter name code and capacity"); ab.putdata(sc.nextLine(), sc.nextInt(), sc.nextInt()); ab.getdata(); } } |
Q.no 14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
import java.util.Scanner; /** * * @author bim study notes */ class y2018q14 { public static void main(String args[]){ System.out.println("Enter the size of array"); int a=new Scanner(System.in).nextInt(); String s[]=new String[a]; System.out.println("Enter "+a+" String"); for(int i=0;i<a;i++){ s[i]=new Scanner(System.in).next(); } for(int i=0;i<a;i++){ s[i]=s[i].replace('i', '!'); } System.out.println("After replace\n\n"); for(int i=0;i<a;i++){ System.out.println(s[i]); } } } |
Q.no 15
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
import java.io.*; import java.util.*; /** * * @author bim study notes */ public class y2018q15 { public static void main(String args[]) { try { String add, name, clz; int i; File f = new File("c:\\myjava"); if (!f.exists()) { f.mkdir(); } File f1 = new File(f, "student.txt"); FileWriter f2 = new FileWriter(f1); System.out.println("name address clz"); name = new Scanner(System.in).next(); add = new Scanner(System.in).next(); clz = new Scanner(System.in).next(); f2.write(" Name=" + name + " add=" + add + " clz=" + clz); System.out.println(); f2.flush(); File f3 = new File(f, "pupil.txt"); FileReader f4 = new FileReader(f1); FileWriter f5 = new FileWriter(f3); int c; { while ((c = f4.read()) != -1) { f5.write((char) c); } } f5.flush(); FileReader f6 = new FileReader(f3); while ((c = f6.read()) != -1) { System.out.print((char) c); } } catch (Exception e) { System.out.println(e); } } } |
Q.no 17
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
package t3rdsem; /** * * @author bim study notes */ class A1 { void msg() { System.out.print("a"); } class B{ void msg() { System.out.print("b"); } class C extends A1 { public ststic void main(String args[]) { C obj=new C(); obj.msg; } } } } } |
Continue Reading