0% found this document useful (0 votes)
8 views8 pages

Positive

The document contains multiple Java programs that perform various tasks such as determining if a number is positive, negative, or zero; finding the greatest of two numbers; checking if a number is even or odd; and printing numbers in different sequences. It also includes functions to find the last and second last digits of a number, and to sum the last digits of two numbers. Each program is structured with user input and conditional statements to achieve the desired functionality.

Uploaded by

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

Positive

The document contains multiple Java programs that perform various tasks such as determining if a number is positive, negative, or zero; finding the greatest of two numbers; checking if a number is even or odd; and printing numbers in different sequences. It also includes functions to find the last and second last digits of a number, and to sum the last digits of two numbers. Each program is structured with user input and conditional statements to achieve the desired functionality.

Uploaded by

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

1.

Positive,Negative or zero

import java.util.Scanner;

class Main {

public static void main(String[] args) {

Scanner S = new Scanner(System.in);

System.out.println("Enter a value for n :");

int n = S.nextInt();

if(n>0){

System.out.println("The given N is Positive");

else if(n<0){

System.out.println("The given N is Negative");}

else{

System.out.println("The given N is Zero");}

2.Greates between two number

import java.util.Scanner;

class Main {

public static void main(String[] args) {

Scanner S = new Scanner(System.in);

System.out.println("Enter a value for a :");

int a = S.nextInt();
System.out.println("Enter a value for b :");

int b = S.nextInt();

if (a > b)

System.out.println("A is greater "+a);

else

System.out.println("B is greater "+b);

3.Even or odd

import java.util.Scanner;

class Main {

public static void main(String[] args) {

Scanner S = new Scanner(System.in);

System.out.println("Enter a value for n :");

int n = S.nextInt();

if(n%2==0){

System.out.println("The given N is Even");

// else if(n<0){

// System.out.println("The given N is Negative");}

else{

System.out.println("The given N is Odd");}

}
4.even or odd with addition of two number

import java.util.Scanner;

class Main {

public static void main(String[] args) {

Scanner S = new Scanner(System.in);

System.out.println("Enter a value for n :");

int n = S.nextInt();

System.out.println("Enter a value for n :");

int m = S.nextInt();

int a = n+m ;

System.out.println("The addition of two number is :"+a);

if(a%2==0){

System.out.println("The addition of two number is Even");

// else if(n<0){

// System.out.println("The given N is Negative");}

else{

System.out.println("The addition of two number is Odd");}

1.Print all numbers from 1 to 100


class Main {

public static void main(String[] args) {

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

System.out.print(i+” “);

2.Print alternatative numbers from 1 to 100(1,3,5,7…)

class Main {

public static void main(String[] args) {

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

System.out.print(i+" ");

i=i+1;

3. Print alternatative numbers from 1 to 100(0,2,4…)

class Main {

public static void main(String[] args) {

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

System.out.print(i+" ");

i=i+1;

}
4.print all number in reverse order from 100 to 0

class Main {

public static void main(String[] args) {

for(int i=100;i>=0;i--){

System.out.print(i+" ");

// i=i+1;

5.print all number from 100 to 0 by skipping 2

class Main {

public static void main(String[] args) {

for(int i=100;i>=0;i--){

System.out.print(i+" ");

i=i-2;

1. isEven

import java.util.Scanner;

class Main {

public static void main(String[] args) {

Scanner s = new Scanner(System.in);

System.out.println("Enter a number :");


int a = s.nextInt();

if (a%2==0 || a==0)

System.out.println(1);

else

System.out.println(2);

2. isOdd

import java.util.Scanner;

class Main {

public static void main(String[] args) {

Scanner s = new Scanner(System.in);

System.out.println("Enter a number :");

int a = s.nextInt();

if (a%2==0 || a==0)

System.out.println(1);

else

System.out.println(2);

3. function that returns the last digit of the given number

import java.lang.Math.*;

import java.util.Scanner;

class Main {
public static void main(String[] args) {

Scanner s = new Scanner(System.in);

System.out.print("Enter a value :");

int num = s.nextInt();

int result = Math.abs(num%10);

System.out.println(result);

4. Second last digit of number

import java.lang.Math.*;

import java.util.Scanner;

class Main {

public static void main(String[] args) {

Scanner s = new Scanner(System.in);

System.out.print("Enter a value :");

int num = s.nextInt();

int result = Math.abs((num/10)%10);

System.out.println(result);

5. Sum of last digit of two number

import java.lang.Math.*;

import java.util.Scanner;

class Main {

public static void main(String[] args) {


Scanner s = new Scanner(System.in);

System.out.print("Enter a value of num1 :");

int num1 = s.nextInt();

System.out.print("Enter a value of num2 :");

int num2 = s.nextInt();

int result1 = Math.abs(num1%10);

int result2 = Math.abs(num2%10);

System.out.println(result1+result2);

You might also like