## RYTWAYS Fresher Interview Questions with Answers – Part 3

### 11. Write a Java program to transpose a matrix .

#### Java Program to transpose matrix

Converting rows of a matrix into columns and columns of a matrix into row is called transpose of a matrix.

Let’s see a simple example to transpose a matrix of 3 rows and 3 columns.

1. publicclass MatrixTransposeExample{
2. publicstatic void main(String args[]){
3. //creating a matrix
4. intoriginal[][]={{1,3,4},{2,4,3},{3,4,5}};
5. //creating another matrix to store transpose of a matrix
6. inttranspose[][]=new int;  //3 rows and 3 columns
7. //Code to transpose a matrix
8. for(inti=0;i<3;i++){
9. for(intj=0;j<3;j++){
10. transpose[i][j]=original[j][i];
11. }
12. }
13. out.println(“Printing Matrix without transpose:”);
14. for(inti=0;i<3;i++){
15. for(intj=0;j<3;j++){
16. out.print(original[i][j]+” “);
17. }
18. out.println();//new line
19. }
20. out.println(“Printing Matrix After Transpose:”);
21. for(inti=0;i<3;i++){
22. for(intj=0;j<3;j++){
23. out.print(transpose[i][j]+” “);
24. }
25. out.println();//new line
26. }
27. }}

Output:

### 12 . Write a Java program to swap two numbers without using temporary variable .

 Write a program to swap or exchange two numbers without  using any temporary or third variable to swap.

Code:
?

 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 package com.java2novice.algos;   public class MySwapingTwoNumbers {       public static void main(String a[]){         int x = 10;         int y = 20;         System.out.println(“Before swap:”);         System.out.println(“x value: “+x);         System.out.println(“y value: “+y);         x = x+y;         y=x-y;         x=x-y;         System.out.println(“After swap:”);         System.out.println(“x value: “+x);         System.out.println(“y value: “+y);     } }

 Output: Before swap: x value: 10 y value: 20 After swap: x value: 20 y value: 10

### 13 . Write a Java program to print the source code .

public class SourcePrint {

private static final long serialVersionUID = 1L;

public void test(){

System.out.println(“Hi I’m test”);

}

public static void main(String[] args) {

new SourcePrint().test();

}

}

### 14 . Write a Java program to print Hello without using semicolon .

#### C Program to print “hello” without semicolon

We can print “hello” or “hello world” or anything else in C without using semicolon. There are various ways to do so:

1. Using if
2. Using switch

#### Program 1: Using if statement

Let’s see a simple c example to print “hello world” using if statement and without using semicolon.

1. #include<stdio.h>
2. int main()
3. {
4. if(printf(“hello world”)){}
5. return0;
6. }

Output:

hello world