0% found this document useful (0 votes)
16 views2 pages

Project Programs 8,9,10

This document contains the code for 3 separate Java methods: 1) The main4() method takes user input of numbers n and calculates separate sums of positive even, positive odd, negative even, and negative odd numbers. 2) The main5() method takes user input of n numbers, tracks the largest even and smallest odd numbers. 3) The main6() method takes a user input number, converts it to a string, and prints the last digit followed by the number of digits.

Uploaded by

Shasumith
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)
16 views2 pages

Project Programs 8,9,10

This document contains the code for 3 separate Java methods: 1) The main4() method takes user input of numbers n and calculates separate sums of positive even, positive odd, negative even, and negative odd numbers. 2) The main5() method takes user input of n numbers, tracks the largest even and smallest odd numbers. 3) The main6() method takes a user input number, converts it to a string, and prints the last digit followed by the number of digits.

Uploaded by

Shasumith
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/ 2

import java.util.

*;
public class page231
{
public static void main4()
{
Scanner in=new Scanner(System.in);
int i,n,ch,spe=0,spo=0,sne=0,sno=0; double num=0.0;
do{
System.out.println("Enter value of n");
n=in.nextInt();
for(i=0;i<n;i++)
{
System.out.println("Enter n numbers");
num=in.nextDouble();
if(num>0&&num%2==0)
spe+=num;
if(num>0&&num%2!=0)
spo+=num;
if(num<0&&num%2==0)
sne+=num;
if(num<0&&num%2!=0)
sno+=num;
}
System.out.println("Sum of positive even=" +spe);
System.out.println("Sum of positive odd=" +spo);
System.out.println("Sum of negative even=" +sne);
System.out.println("Sum of negative odd=" +sno);
for(i=0;i<5;i++)
{}
System.out.println("Enter 0 to terminate");
ch=in.next().charAt(0);
}
while(ch!='0');
}
public static void main5()
{
Scanner in=new Scanner(System.in);
int i,n,ch=0;
double num,max,min;
System.out.println("Enter value of n");
n=in.nextInt();
max=n;min=n;
while(ch!='0')
{ for(i=1;i<=10;i++)
{
System.out.println("Enter numbers");
num=in.nextDouble();
if(num%2==0)
{
if(num>max)
max=num;
}
if(num%2!=0)
{
if(num<min)
min=num;
}
}
System.out.println("largest even=" +max);
System.out.println("smallest odd =" +min);
System.out.println("Enter 0 to terminate");
ch=in.next().charAt(0);
}
}
public static void main6()
{
Scanner in=new Scanner(System.in);
int i=0,j;
System.out.println("Enter number");
int a=in.nextInt();
int num=a;
while(a!=0)
{
a=a/10;
i++;
}
String n=Integer.toString(i);
int sup=num%10;
String u=Integer.toString(sup);
System.out.print(u+n);
}
}

You might also like