0% found this document useful (0 votes)
46 views6 pages

Name:-Roll No: - Class:-: Badugula Rohan Reddy 20009 CSEA / Group-A

The document contains the details of a lab assignment submitted by Badugula Rohan Reddy of class CSEA/Group-A. It includes the code and output for 5 programs: 1) Checking the sign of an integer, 2) Checking if a number is composite, 3) Checking if a number is a duck number, 4) Converting an octal number to hexadecimal, and 5) Printing a pattern.

Uploaded by

rohan reddy
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)
46 views6 pages

Name:-Roll No: - Class:-: Badugula Rohan Reddy 20009 CSEA / Group-A

The document contains the details of a lab assignment submitted by Badugula Rohan Reddy of class CSEA/Group-A. It includes the code and output for 5 programs: 1) Checking the sign of an integer, 2) Checking if a number is composite, 3) Checking if a number is a duck number, 4) Converting an octal number to hexadecimal, and 5) Printing a pattern.

Uploaded by

rohan reddy
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/ 6

LAB – 2

NAME :- Badugula Rohan Reddy


Roll no :- 20009
Class :- CSEA / Group-A

1) Sign of integer.
Code:-
package com.company;
import java.util.Scanner;
public class Ass_3_1 {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number");
int num = sc.nextInt();
if(num > 0)
{
System.out.println("Positive");
}
else if(num == 0)
{
System.out.println("Zero");
}
else{
System.out.println("Negative");
}
}
}

Output :-

2)Check of Composite number.


Code:-
package com.company;
import java.util.Scanner;
public class Ass_3_2 {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number");
int num = sc.nextInt();
int flag = 0;
for(int i = 2 ; i <= num/2 ; i++)
{
if(num%i == 2)
{
flag = 1;
}
}
if(flag == 1)
{
System.out.println("Yes");
}
else
{
System.out.println("No");
}

}
}

Output :-

3)Check of Duck number.


Code:-
package com.company;
import java.util.Scanner;
public class Ass_3_3 {
public static void main(String[]args){
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number :");
String str = sc.nextLine();
int l = str.length();
int ctr = 0;
char chr;

for(int i=1;i<l;i++)
{
chr = str.charAt(i);
if(chr=='0')
ctr++;
}

char f = str.charAt(0);

if(ctr>0 && f!='0')


System.out.println("Duck number");
else
System.out.println("Not a duck number");

}
}

Output:-

4) Octal to Hexadecimal Conversion.


Code:-
package com.company;
import java.util.Scanner;
public class Ass_3_4 {
public static void main(String[] args)
{
String octnum, hexnum;
int decnum;
Scanner scan = new Scanner(System.in);

System.out.print("Enter Octal Number : ");


octnum = scan.nextLine();

decnum = Integer.parseInt(octnum, 8);


hexnum = Integer.toHexString(decnum);

System.out.print("Equivalent Hexadecimal Value of " +


octnum + " is : \t");
System.out.print(hexnum);
}
}

Output:-

5) Pattern.
Code:-
package com.company;
import java.util.Scanner;
public class Ass_3_5 {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
for (int i = 1 ; i<=num ; i++)
{
for(int j = 1 ; j <= i ; j++)
{
System.out.print(j +" ");
}
System.out.println("");
}
}
}

Output:-

You might also like