Professional Documents
Culture Documents
ASSIGNMENT – I
import java.util.Scanner;
public class Oddeven
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int i=sc.nextInt();
switch (i%2)
{
case 1:
System.out.println("The given number is Odd");
break;
default:
System.out.println("The given number is Even");
}
}
}
2) SIGN OF NUMBER:
import java.util.Scanner;
public class Sign
{
public static void main(String s[])
{
int i;
Scanner sc=new Scanner(System.in);
i=sc.nextInt();
if(i<0)
System.out.println("The given number is Negatiive");
else if(i>0)
System.out.println("The given number is Positive");
else
System.out.println("The given number is zero");
}
}
3) MEAN OF NUMBERS:
import java.util.Scanner;
public class Mean
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int i=sc.nextInt();
int j=sc.nextInt();
int k=sc.nextInt();
System.out.println("Mean of given numbers is: "+(i+j+k)/3);
}
}
import java.util.Scanner;
public class Maximum
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
int i=sc.nextInt();
int j=sc.nextInt();
if(i<j)
System.out.println(j+" is the maximum between the two");
else if(i>j)
System.out.println(i+" is the maximum between the two");
else
System.out.println("Both numbers are same");
}
}
5) LOOP 1:
6) LOOP 2:
else
System.out.println(i);
j+=2;
}
}
}
7) LOOP 3:
package assignment;
public class loop3
{
public static void main(String s[])
{
int i=1;
while(i<=17)
{
System.out.println(i);
i+=4;
}
}
}
8) LOOP 4:
9) LOOP 5: