0% found this document useful (0 votes)
10 views

Java Training Feb

Uploaded by

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

Java Training Feb

Uploaded by

Harini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

JAVA TRAINING FEB

05/02/2023

import java.util.*;

class GoodMorning{

public static void main(String[] args) {


Scanner sc = new Scanner(System.in);

int n = sc.nextInt();

for(int i = 1; i <= n ; i++){

if(i%5 == 0 && i%3 == 0){


System.out.println("Good Morning");
}

else if(i%5 == 0){


System.out.println("Morning");
}

else if(i%3 == 0){


System.out.println("Good");
}
else{
System.out.println(i);
}

}
}

---------------------------

import java.util.*;
import java.util.Arrays;

class ArraysRotate{

public static void main(String[] args) {


Scanner sc = new Scanner(System.in);

int arr[] = {1,2,3,4,5};

int n = sc.nextInt();

for(int i = 0; i < n ; i++){

int temp = arr[arr.length-1];

for(int j = arr.length-1 ; j > 0 ; j--){


arr[j]= arr[j-1];

}
arr[0] =temp;

for(int i = 0 ; i < arr.length ; i++){


System.out.print(arr[i]+" ");
}

}
}

// 3
// 3 4 5 1 2

// for(int i = 0; i < n ; i++){

// int temp = arr[0];

// for(int j = 0 ; j < arr.length-1 ; j++){


// arr[j]= arr[j+1];

// }
// arr[arr.length-1] =temp;

// }

// for(int i = 0 ; i < arr.length ; i++){


// System.out.print(arr[i]+" ");
// }

// }
// }

// 3
// 4 5 1 2 3

---------------

import java.util.*;
import java.io.*;

class RightTriangle {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();

for (int i = 0; i < n ; i++ , System.out.println()){


for ( int j = 0 ; j <= i ; j++){
System.out.print("*");
}

}
}
}
5
*
**
***
****
*****

------------------
Home work

get the number , count the iterations that the number's square

import java.util.Scanner;

public class SquareCount {

public static void main(String[] args) {


Scanner sc = new Scanner(System.in);

int n = sc.nextInt();

int count = 0 , x = 0 ;

while(n > 0) {
for(int i = 1 ; i < n ; i++){
int s = i * i ;
if( s < n){
x = s ;

}
}
n = n - x;
count++;

}
System.out.println(count);
}

-----------------------------------------------------

06/02/2024

You might also like