Javatpoint Logo

Core Java Programs

By: smitak*** On: Thu May 04 12:37:29 IST 2017     Question Reputation0 Answer Reputation0 Quiz Belt Series Points0  0Blank User
1. You are given an Integer N, print N+1 lines in the following manner

case 1:

If N=3, then the pattern would be -

3 3 3
3 1 3
3 2 3
3 3 3

case 2: If N=4, then the pattern would be -

4 4 4 4 4
4 4 1 4 4
4 4 2 4 4
4 4 3 4 4
4 4 4 4 4



2. An image is represented by an m*n matrix of integers, where each integer represents a pixel

value

Write a method to return an image by 90 degrees left or right according to the value of flag

variable.

If the flag value is 0 then rotate to the left. If the flag value is 1 then rotate to the

right.

The inputs to the method rotatePictureMethod of class RotatePicture consist of the matrix and

value of the flag respectively.

The method should return a two dimensional matrix that is rotated according to the input flag

value.


For example

If flag=1

Input Matrix Output Matrix

1 2 3 7 4 1
4 5 6 8 5 2
7 8 9 9 6 3




Up0Down

 
Image Created0Down

By: [email protected] On: Fri May 05 09:51:31 IST 2017 Question Reputation0 Answer Reputation0 Belt Series Points0 0User Image
Are You Satisfied :0Yes0No
 
Image Created0Down

By: [email protected] On: Mon May 08 11:31:13 IST 2017 Question Reputation0 Answer Reputation0 Belt Series Points0 0User Image
Are You Satisfied :0Yes0No
 
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

package javaapplication11;

import java.util.Scanner;

/**
*
* @author SATVIK
*/
public class JavaApplication11 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
try{
Scanner sc=new Scanner(System.in);
int n;
System.out.print("Enter n:");
n=sc.nextInt();

int [][]aray=new int[n][n];

int temp= n -(n-1);
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(j==(n/2) && i>0)
{
aray[i][j]=temp;
temp++;
}
else if(j==(n/2) && i==0)
{
aray[i][j]=n;
}
else
{
aray[i][j]=n;
}

}


}



System.out.print("Array \n");
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
System.out.print(aray[i][j]);
}
System.out.println("");

}
int i=n-1;
if(i==(n-1))
{
for (int j=0;j<n;j++)
{System.out.print(n);}
}

}
catch(Exception e)
{
System.out.print(e);
}
}

}
Image Created0Down

By: [email protected] On: Mon May 08 12:26:14 IST 2017 Question Reputation0 Answer Reputation0 Belt Series Points0 0User Image
Are You Satisfied :0Yes0No