0% found this document useful (0 votes)
5 views41 pages

Assignment-1..java Total

The document contains a series of Java programming assignments demonstrating various concepts such as inheritance, bitwise operators, the 'super' and 'this' keywords, variable scope, and the 'final' keyword. Each assignment includes code snippets, expected outputs, and explanations of the concepts being illustrated. The assignments cover topics like multiple inheritance, interfaces, default and static methods, and error handling in Java.

Uploaded by

Rahul Kumar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views41 pages

Assignment-1..java Total

The document contains a series of Java programming assignments demonstrating various concepts such as inheritance, bitwise operators, the 'super' and 'this' keywords, variable scope, and the 'final' keyword. Each assignment includes code snippets, expected outputs, and explanations of the concepts being illustrated. The assignments cover topics like multiple inheritance, interfaces, default and static methods, and error handling in Java.

Uploaded by

Rahul Kumar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Assignment:-1

Q)Write a java program to create a multi level Inheritance.


class A {
void showA() {
[Link]("this is class A");
}
}
class B extends A {
void showB () {
[Link]("this is class B");
}}
class C extends B {
void showC () {
[Link]("this is class C");
}}
public class Main {
public static void main(String[] args) {
C obj = new C();
[Link]();
[Link]();
[Link]();
}}
OUTPUT:-
this is class A
this is class B
this is class C
=== Code Execution Successful ===
Assignment:-2
W.A.P to java to demonstrate the application of bitwise operator.
class bit{
public static void main(String[] args){
int x = 7;
int y = 20;
int z = x & y;
[Link](z);
}
}
OUTPUT:-
4
=== Code Execution Successful ===
Assignment:-3
W.A.P in java to demonstrate the application of super keyword
class shikha{
int x =10;
shikha(int y){
[Link]("inside shikha class");
[Link](y); }
public void show(){
[Link]("this is ths class shikha show method"); } }
class B extends shikha{
int x = 20;
B(){
super(50);
[Link]("inside class B"); }
public void show(){
[Link]();
[Link](x);
[Link](super.x);
}}
public class Main {
public static void main(String[] args){
B obj = new B();
[Link]();
}}
OUTPUT:-inside shikha class
50
inside class B
this is ths class shikha show method
20
10

=== Code Execution Successful ===


Assignment:-4
W.A>p in java to demonstrate the application oh this keyword.
class A {
public int x = 10;
A() { this(25);
[Link]("inside class A"); }
A(int y) {
[Link](y); }}
class B extends A {
public int x = 20; B() {
[Link]("inside class B");
} public void show() {
[Link]("this is the class B show method");
} public void display() {
[Link](); int x = 30;
[Link]("this is the class B display method");
[Link](this.x);
[Link](x);} }
public class Main {
public static void main(String[] args) {
B obj = new B();
[Link](); }}OUTPUT:-25
inside class A inside class B
this is the class B show method
this is the class B display method
20 30
=== Code Execution Successful ===
Assignment:-5
W.A.P in java to demonstrate the scope of three variable
class A {
static int z = 30;
public int x = 10;
A() {
[Link]("inside class A");
}
public void show() {
int y = 20;
[Link](x);
[Link](y);
[Link](z);
}}
public class Main {
public static void main(String[] args) {
A obj = new A();
[Link]();
}}
OUTPUT:-
inside class A
10
20
30

=== Code Execution Successful ===


Assignment:-6
Q) Write a java program to demonstrated final keyword.
final class Shikha{
final int X = 10;
final public void show(){
[Link]("this is the final show method");
[Link](X);
}}
public class Main {
public static void main(String[] args){
Shikha obj = new Shikha();
[Link]();
}
}
OUTPUT:-
this is the final show method
10
=== Code Execution Successful ===
Assignment:-7
Q)Write a java program to demonstrated static block, static variable, static method and nested inner class.
class shikha{
static int x;
static{
x = 50;
[Link]("static block execute"); }
static void show(){
[Link]("Static method");
[Link](x);
} static class inner{
public void display(){
[Link]("static nasted class");
[Link](x);
} }}
public class Main {
public static void main(String[] args){
[Link]();
[Link] ob = new [Link]();
[Link]();
}}
OUTPUT:-static block execute
Static method
50
static nasted class
50
=== Code Execution Successful ===

Assignment:-8
Q) we can not make a private constructor in java program(show the error)
class shikha{
public int x = 10;
public shikha(){
[Link]("inside class shikha"); }
public void show(){
[Link](x);
}
}
public class Main {
public static void main(String[] args){
shikha ob = new shikha();
[Link]();
}
}
OUTPUT:-
inside class shikha
10
=== Code Execution Successful ===
Assignment:-9
Q)write a java program to implement facts java does not support mode of Access Specifiers .
class Shikha {
public int x = 10;
Shikha() {
[Link]("inside class Shikha");
}}
class B extends Shikha {
public void show() {
[Link]("this is the show method");
[Link](x);
}}
public class Main {
public static void main(String[] args) {
B obj = new B();
[Link]();
}}
OUTPUT:-
inside class Shikha
this is the show method
10

=== Code Execution succesful===


Assignment:-10
Q)write a java program to demonstrated that show the facts that java does not support multiple inheritance.
class Shikha {
public int x = 10;
Shikha() {
[Link]("inside class Shikha Constructor");
} }class Kajal {
public int y = 20;
Kajal() {
[Link]("inside class Kajal Constructor"); }}
class Both {
public int z = 30;
Shikha shikhaObj;
Kajal kajalObj;
Both() {
shikhaObj = new Shikha();
kajalObj = new Kajal();
[Link]("inside class Both Constructor"); }
public void show() {
[Link](shikhaObj.x);
[Link](kajalObj.y);
[Link](z); }}
public class Main {
public static void main(String[] args) {
Both obj = new Both();
[Link]();}}
OUTPUT:-inside class Shikha Constructor
inside class Kajal Constructor
inside class Both Constructor
10
20
30=== Code Execution Successful ===

Assignment:-11
[Link] we implement multiple interface
interface A {
void disp();
}

interface B {
void display();
}

class Rectangle implements A,B {


public void disp() {
[Link]("Implement to Interface A");
}

public void display() {


[Link]("Implementing to Interface B");
}
}

public class Main {


public static void main(String[] args) {
Rectangle obj = new Rectangle();
[Link]();
[Link]();
}
}
OUTPUT:-
Implement to Interface A
Implementing to Interface B
=== Code Execution Successful ===
Assignment:-12
12. Can i reinitialize a variable in an implementing class? means,you have initializes a variable inside an interface and want to assign a value again in the
class implementing it,can you do this?
interface A {
int x = 10;
}

class Simple implements A {


int x = 50;
void display() {
[Link]("Value of x: " + x);
[Link]("Value of x: " + A.x);
}}
public class Main {
public static void main(String[] args) {
Simple obj = new Simple();
[Link]();
}
}
OUTPUT:-
Value of x: 50
Value of x: 10
=== Code Execution Successful ===
Assignment:-13
[Link] you redefine a default and static method defined in interface,in the class implementing it?
interface A {
default void disp() {
[Link]("Default method called");
}
static void display() {
[Link]("Satic method called");
}
}
class Demo implements A {
public void disp() {
[Link]("Default method redefined");
}
static void display() {
[Link]("Static method redefined");
}
}
public class Main {
public static void main(String[] args) {
Demo obj = new Demo();
[Link]();
[Link]();
}
}
OUTPUT:-
Default method redefined
Satic method called

=== Code Execution Successful ===


Assignment:-14
Q)This can a method be a default & static both in an
interface.
INPUT:-
interface shikha{
default static void show(){
[Link]("this is the interface method ");
}
}
class A implements shikha {
}
public class Assignment_14 {
public static void main(String[] args){
A obj = new A();
[Link]();
}

}
OUTPUT:-
default static void show(){
^
Assignment_14.java:13: error: cannot find symbol
[Link]();
^
symbol: method show()
location: variable obj of type A
2 error
Assignment:-15
Q) Write a java program that has to interface.
Interface -> A,B,C
Class :- D -> A & B
Class:- E-> D & C
INPUT:-
interface A{
public void Print(); }
interface B {
public void Show(); }
interface C{
public void Display(); }
class Student implements A,B{
public void Print(){
[Link]("this is the print method define
class Student ");
}
public void Show(){
[Link]("this is the show method inside
the class Student"); } }
class Child extends Student implements C{
public void Display(){
[Link]("this is the Display method inside
class child"); } }
public class Assignment_15
public static void main(String[] args){
Student ob1 = new Student();
Child ob2= new Child();
[Link]();
[Link]();
[Link]();
}
}
OUTPUT:-
this is the print method define class Student
this is the show method inside the class Student
this is the Display method inside class child
Assignment:-16
Q) Can we implement multiple inheritance?.
interface A {
public void show();
}
interface B{
public void display();}
interface C{
public void Print();
}
class shikha implements A,B,C{
public void show(){
[Link]("this is the show method");
}
public void display(){
[Link]("this is the display method");}
public void Print(){
[Link]("this is the Print method");
}}
public class Assignment_01 {
public static void main(String[] args){
shikha obj = new shikha();
[Link]();
[Link]();
[Link]();} }
OUTPUT:-this is the show method
this is the display method
this is the print methode
Assignment:-17
Q. CAN I REINITIALISE A VARIABLE IN AN IMPLEMENTING CLASS?MEANS .YOUHAVE INITIALISED A
VARIABLE INSIDE AN INTERFACE AND WANT TO ASSIGN A AGAIN IN THE CLASS IMPLEMENTING IT
CAN YOU DO THIS?
Input:-
Interface A{
Int x= 10
Int y=20;
}
Class B implement A{
X= 40;
Y=50;
Public void show(){
[Link](x);
[Link](y);
[Link](z);
}
}
Public class main {
Public static void main() {
B obk = new B();
[Link]();
}}
OUTPUT:- [Link]: error: expected
X = 40
^
[Link]:error:expected
Y = 50
^
Assignment:-18
1. CAN YOU REDEFINE A DEFAULT AND STATIC METHOD DEFINED AND
STATICMETHOD DEFINED IN INTERFACE IN THE CLASS IMPLEMENTING IT?
interface shikha{
default void show(){
[Link]("this is the show method");
}
static void display(){
[Link]("this is the display method");
}
}
class A implements shikha{
public void show(){
[Link]("inside the class a show method");
}
public void display(){
[Link]("inside the class a display
method");
}
}
public class Assignment_3 {
public static void main(String[] args){
A obj = new A();
[Link]();
[Link]();
}
}
OUTPUT:-
inside the class a show method
inside the class a display method
Assignment:-19
Q)Can you inherit a class and an interface together what is the order of writing
the inheritance ? Means what to write frist extending a class or implementing an
interface.
interface A{
public void Add();
}
interface B{
public void show();
}
interface C{
public void display();
}
class shikha implements A,B{
public void Add(){
[Link]("this is the add method");
}
public void show(){
[Link]("this is the show method");
}
}
class suman extends shikha implements C{
public void display(){
[Link]("this is the display method");
}
}
public class Assignment_04 {
public static void main(String[] args){
suman obj = new suman();
[Link]();
[Link]();
[Link]();
}}
OUTPUT:-
this is the add method
this is the show method
this is the display method
Assignment:-20
Q) What will happened when you don’t implement an abstract method declared
in interface in the class implementing it?
interface shikha{
public void show();
public void display();
}
class A implements shikha{
}
public class Assignment_5 {
public static void main(String[] args){
A obj = new A();
[Link]();
[Link]();
}
}
OUTPUT:-
Assignment_5.java:15: error: cannot find symbol
[Link]();
^
symbol: method show()
location: variable obj of type A
Assignment_5.java:16: error: cannot find symbol
[Link]();
^
symbol: method display()
location: variable obj of type A
Assignment:-21
Q) Can interface have Constructor?
interface shikha{
Add();
}
class Add implements shikha{
public int x = 10;
public void Add(){
[Link]("this is the class Add
constructor");
[Link](x);
} }
public class Assignment_6 {
public static void main(String[] args){
Add obj = new Add();
}}
OUTPUT:-
Assignment_6.java:4: error: <identifier> expected
Add();
^
1 error
Assignment:-22
Q) Suppose a class Is implementing both A & B interface? Both methods in it Then
how can it be alone?means what will be the syntax of mentioning add() method
of interface A in class C?.
interface A{
void Add();
}
interface B{
void Add(int y);
}
class shikha implements A,B{
public void Add(){
[Link]("Add method of interface A");
}
public void Add(int y){
[Link]("Add method of interface B");
}
}
public class Assignment_o7copy {
public static void main(String[] args){
shikha obj = new shikha();
[Link]();
[Link](10);
}
}
OUTPUT:-
Add method of interface A
Add method of interface B
Assignment:-23
Q) Can I define default method in a class rather than an interface?
interface Num{
public default void Show(){
[Link]("this is interface NUM show
method");
}
}
class shikha implements Num{
public void Show(){
[Link]("this is class shikha show
method");
}
}
public class Assignment_8 {
public static void shikha(String[] args){
shikha obj = new shikha();
[Link]();
}
}
OUTPUT:-
Error: Main method not found in class Assignment_8, please
define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend
[Link]
Assignment:-24
Q) Can I create an abstract class implementing an interface?
interface A{
public void Show();
}
abstract class shikha implements A{
}
class B extends shikha{
public void Show(){
[Link]("inside class B Show method");
}
}
public class Assignment_9 {
public static void main(String[] args){
B obj = new B();
[Link]();
}

}
OUTPUT:-
inside class B Show method
Assignment:-25
Q) Can a method in an interface be protected?
interface A {
protected void show();
}
class shikha implements A{
public void show(){
[Link]("this is the show method inside
the class");
}
}
public class Assignment_10 {
public static void main(String[] args){
shikha obj = new shikha();
[Link]();
}

}
OUTPUT:-
Assignment_10.java:4: error: modifier protected not allowed
here
protected void show
1 error
Assignment:-26
What will happened when you create an abstract method
declared in interface but not define inside the
implementing class it?
INPUT:-
interface A{
public void show();
}
class shikha implements A{
}
public class Abstract1 {
public static void main(String[] args){
shikha obj = new shikha();
[Link]();
}

}
OUTPUT:-
[Link]: error: shikha is not abstract and does not
override abstract method show() in A
class shikha implements A{
^
[Link]: error: cannot find symbol
[Link]();
^
symbol: method show()
location: variable obj of type shikha
2 error
Assignment:-27
What will happened when you create an default method
declared in interface and inside implementing class same
method name.
INPUT:-
interface A{
public default void show(){
[Link]("this is the show method inside
interface");
}
}
class shikha implements A{
public void show(){
[Link]("this is the show method inside
the shikha class");
[Link]();
}
}
public class Assignment_27 {
public static void main(String[] args){
shikha obj =new shikha();
[Link]();
}

}
OUTPUT:-
this is the show method inside the shikha class
this is the show method inside interface
ASSIGNMENT-28
Q.1) W.A.J.P THAT HANDLES AN EXCEPTION TRY ,CATCH.
CODE:
// Online Java Compiler
// Use this editor to write, compile and run your Java code online
public class A {

public static void main(String[] args) {


try {
int a = 10;
int b = 0;
int result = a / b;

[Link]("Result: " + result); }


catch (ArithmeticException e) {
[Link](" Division by zero is not allowed."); } } }

OUTPUT:
Division by zero is not allowed.

=== Code Execution Successful ===

Q.2) W.A.J.P THAT HANDLES AN EXCEPTION TRY ,FINALLY.


CODE:
public class A {
public static void main(String[] args) {

try {
int a = 10;
int b = 0;
int result = a / b;
[Link]("Result: " + result); } finally {

[Link]("This block always executes.");


}}}

OUTPUT:
This block always executes.
ERROR!

Exception in thread "main" [Link]: / by zero


at [Link]([Link])
=== Code Exited With Errors ===
Q.3) W.A.J.P THAT HANDLES AN EXCEPTION TRY ,CATCH,FINALLY.
CODE:

public class A {
public static void main(String[] args) {
try {
int a = 10;
int b = 0;

int result = a / b;
[Link]("Result: " + result);
}
catch (ArithmeticException e) {
[Link](" Division by zero is not allowed.");

}
finally {
[Link]("This block always executes.");
}
}

OUTPUT:
Division by zero is not allowed.
This block always executes.

=== Code Execution Successful ===


ASSIGNMENT-29

Q.1) W.A.J.P THAT HANDLES AN EXCEPTION ARRAY INDEX OUT OF BOUNDS EXCEPTION.
CODE:
class ArrayException {
public static void main(String[] args) {

int a[] = new int[5];

try {
a[8] = 10;
[Link]("executable code");

}
catch (ArrayIndexOutOfBoundsException e) {
[Link]("Array index out of bound");
}
finally{

[Link]("executable code");
} }}

OUTPUT:
Array index out of bound
executable code

=== Code Execution Successful ===


ASSIGNMENT-30
Q.1) W.A.J.P THAT HANDLES AN EXCEPTION MULTIPLE CATCH BLOCK.
CODE:
class MultipleCatchExample {
public static void main(String[] args) {
try {

int a = 10 / 0;
int arr[] = new int[5];
arr[10] = 8; }
catch (ArithmeticException e) {
[Link]("Arithmetic Exception handled"); }

catch (ArrayIndexOutOfBoundsException e) {
[Link]("Array Index Out Of Bound");
}
catch (Exception e) {
[Link]("General Exception");

}
}
}
OUTPUT:
Arithmetic Exception handled
=== Code Execution Successful ===
ASSIGNMENT-31

Q.1) W.A.J.P THAT HANDLES AN EXCEPTION NESTED TRY BLOCK.


CODE:
class NestedTryExample {
public static void main(String[] args) {

try { try {
int a = 10 / 0;
}
catch (ArithmeticException e) {
[Link]("Inner catch: Arithmetic Exception"); }

int arr[] = new int[5];


arr[8] = 20; }
catch (ArrayIndexOutOfBoundsException e) {
[Link]("Outer catch: Array Index Out Of Bound");
}}}

OUTPUT:
Inner catch: Arithmetic Exception
Outer catch: Array Index Out Of Bound

=== Code Execution Successful ===


ASSIGNMENT-32

Q.1) W.A.P IN JAVA THAT DEMONSTRATE THE APPLICATION OF THROW KEYWORD.


CODE:
class ThrowExample {
public static void main(String[] args) {

int age = 15;


if (age > 18) {
throw new ArithmeticException("Not eligible to vote"); } else {
[Link]("Eligible to vote");
}}}

OUTPUT:
Eligible to vote
=== Code Execution Successful ===

Q.2) W.A.P IN JAVA THAT DEMONSTRATE THE APPLICATION OF THROW KEYWORD USING METHOD.
CODE:
class ThrowExample {
static void myHandler(int age) {
try {
if (age < 18) {
throw new ArithmeticException("Underage");

} else {
[Link]("You are eligible");
}
} catch (ArithmeticException e) {
[Link]("Exception caught");

[Link]([Link]());
} }
public static void main(String[] args) {
myHandler(18); } }
OUTPUT:

You are eligible

=== Code Execution Successful ===


ASSIGNMENT-33
Q.1) W.A JAVA PROGRAM THAT DEMONSTRATE THROWS KEYWORD .
CODE:
class ThrowsExample {
static void myMethod() throws ArithmeticException {
int a = 10 / 0;

[Link](a);
}

public static void main(String[] args) {


try {

myMethod();
}
catch (ArithmeticException e) {
[Link]("BCA stream Sahi hai");
}}}

OUTPUT:
BCA stream Sahi hai
=== Code Execution Successful ===
ASSIGNMENT-34
Q.1) [Link] TO DEMONSTRATE THE USE OF 'THROWS' KEYWORD IN METHOD SIGNATURE.

CODE:

class ThrowsExample {

public static void main(String[] args) {

try {

static void myMethod() throws ArithmeticException {

int a = 10 / 0;

[Link](a);

} }

catch (ArithmeticException e) {

[Link]("BCA stream ");

} }}

OUTPUT:

ERROR!/tmp/9EMIgxc7pO/[Link]: error: illegal start of expression

static void myMethod() throws ArithmeticException {

ERROR!/tmp/9EMIgxc7pO/[Link]: error: 'try' without 'catch', 'finally' or resource declarations

try {

ERROR!/tmp/9EMIgxc7pO/[Link]: error: class, interface, enum, or record expected

catch (ArithmeticException e) {

ERROR!/tmp/9EMIgxc7pO/[Link]: error: class, interface, enum, or record expected

} }}

4 errors

ERROR!

error: compilation failed

=== Code Exited With Errors ===


Assignment:-35
Q)Write a program in java the demonstrated the application of
throws keywords inside the try block
INPUT:-
class Assignment_35{
public static void main(String[]args){
try{
Static void my_method()throws
ArithmeticException{

int a = 20/0;
}
}
catch(ArithmeticException e){
[Link]("you can divide by zero");
}
}
}
OUTPUT:-
Assignment_35.java:5: error: illegal start of expression
Static void my_method()throws ArithmeticException
{
^
Assignment_35.java:5: error: ';' expected
Static void my_method()throws ArithmeticException
{
Assignment_35.java:5: error: ';' expected Static void my_method()throws
ArithmeticException
Assignment:-36
Q)Write a java [Link] implement the use of following string function in
java.
public class Assignment_36 {
public static void main(String[] args){
String x = new String("Shikha");
Syst
[Link](x);
//lenght()
[Link]();
[Link]([Link]());
// CharAt()
[Link](2);
[Link]([Link](2));
//IndexOf()
[Link]([Link]('h'));
//replace()
[Link]([Link]('R', 'P'));
// reverse()
StringBuffer ob = new StringBuffer("Suman");
[Link]([Link]());
}}
OUTPUT:-
shikha
6
a
3
shikha
namuS
ASSIGNMENT-37
Q)Write a java Program that implements the use of following java function.
public class Assignment_37 {
public static void main(String[] args){
String x = new String("Shikha");
//toupperCase()
[Link]([Link]());
//toLowercase()
[Link]([Link]());
//trim()
[Link]([Link]());
//Contains()
[Link]([Link](" sonawane"));
// join()
[Link]([Link]("-","b","h","a","v","n","a"));
//Split()
[Link]("shikha sonawane".split(" "));
//substring()
[Link]([Link](1,4));
//valueOf()
[Link]([Link](100));
//equals()
[Link]([Link]("shikha"));
// JOIN
String s =
[Link]("-","my","name","is","shikha");
[Link](s);
}}
OUTPUT:-
SHIKHA
shikha
Shikha
false
b-h-a-v-n-a
[[Link];@7ad041f3
avn
100
true
my-name-is-shikha
ASSIGNMENT-38
Q) Write a Program in java to add 2 matrix of same Dimensional
public class Assignment_38 {
public static void main(String[] args) {
int[][] x = { {1, 2, 3}, {4, 5, 6} };
int[][] y = { {2, 4, 6}, {8, 10, 12} };
int[][] z = new int[2][3];
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 3; j++) {
z[i][j] = x[i][j] + y[i][j];
}
}
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 3; j++) {
[Link](z[i][j] + "\t");
}
[Link]();
}
}
}
OUTPUT:-
3 6 9
12 15 18
ASSIGNMENT-39
Q) Write a program in java to multiply the value of 2D array with the scare county 7.
public class Assignment_39 {
public static void main(String[] args){
int [][] a = {{2,4},{6,8}};
int [][] b = new int[2][2];
for(int i = 0; i < 2; i++){
for(int j = 0; j < 2; j++){
b[i][j] = 7 * a[i][j];
}
}
for(int i = 0; i < 2; i++){
for(int j = 0; j < 2; j++){
[Link](b[i][j] + "\t");
}
[Link]();
}
}
}
OUTPUT:-
14 28
42 56
Assignment:-40(A)
Q)Write a Program in java the write the without give the size element are inserted.
INPUT:-
public class Assignment_40 {
public static void main(String[] args){
int[][] x = { {1, 2, 3}, {4, 5, 6} };
for(int i = 0; i < 2; i++){
for(int j = 0; j < 2; j++){
[Link](x[i][j] + "\t");
}
}
}}
OUTPUT:-
1 2 4 5

ASSIGNMENT:-40(B)
Q) Write a program in java the write they give the sizeof array element are inserted.
INPUT:-
public class Assignment_40 {
public static void main(String[] args){
int[2][3] x = { {1, 2, 3}, {4, 5, 6} };
for(int i = 0; i < 2; i++){
for(int j = 0; j < 2; j++){
[Link](x[i][j] + "\t");
}
}
}}
OUTPUT:-
Assignment_40.java:5: error: ']' expected
int[2][3] x = { {1, 2, 3}, {4, 5, 6} };
^
Assignment_40.java:5: error: not a statement
int[2][3] x = { {1, 2, 3}, {4, 5, 6} };
^
Assignment_40.java:5: error: illegal start of expression
int[2][3] x = { {1, 2, 3}, {4, 5, 6} };
^
Assignment_40.java:5: error: not a statement
int[2][3] x = { {1, 2, 3}, {4, 5, 6} };
^
Assignment_40.java:5: error: ';' expected
int[2][3] x = { {1, 2, 3}, {4, 5, 6} };
^
Assignment_40.java:5: error: illegal start of expression
int[2][3] x = { {1, 2, 3}, {4, 5, 6} };
^
Assignment_40.java:5: error: not a statement
int[2][3] x = { {1, 2, 3}, {4, 5, 6} };
^
Assignment_40.java:5: error: ';' expected
int[2][3] x = { {1, 2, 3}, {4, 5, 6} };
ASSIGNMENT:-40(c)
Q)Write a program in java that using the Arrays Function.
INPUT:-
import [Link];
public class Assignment_41B {
public static void main(String[]args){
int [] x = {2,3,4,5,6,7};
[Link](x);
[Link]("Sorted Arrays"+
[Link](x));
for(int i=0;i<6;i++){
[Link](x[i] + " ");
}

[Link]("lenght of the String :" +


[Link]);
}}
OUTPUT:-
Sorted Arrays[2, 3, 4, 5, 6, 7]
2 3 4 5 6 7
lenght of the String :6

You might also like