preety
BAN USER
class Main{
static void spiralPrint(int m, int n, int a[][]) {
int i, k = 0, l = 0;
/* k - starting row index
m - ending row index
l - starting column index
n - ending column index
i - iterator
*/
while (k < m && l < n) {
for (i = l; i < n; ++i) {
System.out.print(a[k][i]+" ");
}
k++;
for (i = k; i < m; ++i) {
System.out.print(a[i][n-1]+" ");
}
n--;
if ( k < m) {
for (i = n-1; i >= l; --i) {
System.out.print(a[m-1][i]+" ");
}
m--;
}
if (l < n) {
for (i = m-1; i >= k; --i) {
System.out.print(a[i][l]+" ");
}
l++;
}
}
}
public static void main (String[] args) {
int R = 3;
int C = 6;
int a[][] = { {1, 2, 3, 4, 5, 6},
{7, 8, 9, 10, 11, 12},
{13, 14, 15, 16, 17, 18}
};
spiralPrint(R,C,a);
}
}
class Main{
static void printFirstRepeating(int arr[]) {
int min = -1;
HashSet<Integer> set = new HashSet<>();
for (int i=arr.length-1; i>=0; i--) {
if (set.contains(arr[i]))
min = i;
else
set.add(arr[i]);
}
if (min != -1)
System.out.println("The first repeating element is " + arr[min]);
else
System.out.println("There are no repeating elements");
}
public static void main (String[] args) throws java.lang.Exception {
int arr[] = {10, 5, 3, 4, 3, 5, 6};
printFirstRepeating(arr);
}
}
Repmakaylamelua, Blockchain Developer at AMD
I am a sound editing and music composer with experience of handling a wide variety of programs.During my free ...
RepAlmaRJude, Quality Assurance Engineer at Brocade
I am Alma from Livermore USA, I also enjoy reading – my favourite topics being social history, the development and use ...
RepNatalieLutz, Applications Developer at Absolute Softech Ltd
Pitch trending story topics and continually look for ways to push breaking and/or viral stories forward with new angles ...
Repdavisjerryh, Backend Developer at Abs india pvt. ltd.
For the last two years, I am Effectively managing the team’s performance, conducting regular performance reviews and appraisals, and ...
Reptaylorjose221, Production Engineer at BT
Graphic designer with a strong background in marketing design.Having a day off during the week to do whatever I ...
Repleighpjoyce, job tessio at CapitalIQ
Welcome to my world.I am a safety-conscious HVAC Engineer with experience with mechanical engineering Brampton HVAC design for commercial ...
Repmarybritt, Android Engineer at Centro
I am Mary from Wilmington. I am working as a Graphic Designer in Super Enterprises. I also write articles and ...
Repceciliajbaker24, Area Sales Manager at ABC TECH SUPPORT
I work as an Aide at the Alhambra Maker-space, consulting ASU students who come into the space with their projects ...
Reprachelwrosa1, Computer Scientist at ABC TECH SUPPORT
Hello, I am Rachel and I live in Charleston, USA. I am working as a data entry clerk who is ...
Repsusiejcrider, Member Technical Staff at Accolite software
I was a Communications Consultant with experience in working across various clients .technology, consumer, hospitality, financial services and corporate social ...
Open Chat in New Window
class HappyNumber {
- preety May 08, 2019static int numSquareSum(int n) {
int squareSum = 0;
while (n!= 0) {
squareSum += (n % 10) * (n % 10);
n /= 10;
}
return squareSum;
}
// method return true if n is Happy number
static boolean isHappynumber(int n) {
int slow, fast;
slow = fast = n;
do {
slow = numSquareSum(slow);
fast = numSquareSum(numSquareSum(fast));
} while (slow != fast);
return (slow == 1);
}
public static void main(String[] args) {
int n = 13;
if (isHappynumber(n))
System.out.println(n + " is a Happy number");
else
System.out.println(n + " is not a Happy number");
}
}