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

java2 (1)

The document contains multiple Java programs that perform various tasks, such as identifying character types, finding the largest number among inputs, calculating gross salary based on a given basic pay, applying discounts to bills, and counting the number of digits in a number. Each program uses the Scanner class for input and includes conditional statements to determine the output. The outputs of the programs are also provided as examples.
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)
2 views

java2 (1)

The document contains multiple Java programs that perform various tasks, such as identifying character types, finding the largest number among inputs, calculating gross salary based on a given basic pay, applying discounts to bills, and counting the number of digits in a number. Each program uses the Scanner class for input and includes conditional statements to determine the output. The outputs of the programs are also provided as examples.
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

1.

import java.util.*;

class Main

public static void main(String args[])

Scanner s=new Scanner(System.in);

char str= s.next().charAt(0);

if((str>='a'&&str<='z')||(str>='A'&&str<='Z'))

System.out.println("Alphabet");

else if(str>='0'&&str<='9')

System.out.println("Number");

else

System.out.println("Special character");

Output:

Alpbhabet

2. import java.util.*;

public class Main

public static void main(String[] args) {

Scanner s=new Scanner(System.in);

int n1=s.nextInt();
int n2=s.nextInt();

int n3=s.nextInt();

int n4=s.nextInt();

int n5=s.nextInt();

if(n1>n2&&n1>n3&&n1>n4&&n1>n5)

System.out.println("n1 is largest");

else if(n2>n1&&n2>n3&&n2>n4&&n2>n5)

System.out.println("n2 is largest");

else if(n3>n1&&n3>n2&&n3>n4&&n3>n5)

System.out.println("n3 is largest");

else if(n4>n1&&n4>n2&&n4>n3&&n4>n5)

System.out.println("n4 is largest");

else{

System.out.println("n5 is largest");

Output: 1 3 5 8 0

n4 is largest

3.

import java.util.*;

public class Main

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

Scanner s=new Scanner(System.in);

char a=s.next().charAt(0);

if(a>='a'&&a<='z')

System.out.println("Lower Case");

else if(a>='A'&&a<='Z')

System.out.println("Upper Case");

Output:

Upper Case

5.

import java.util.*;

public class Main

public static void main(String[] args) {

Scanner s=new Scanner(System.in);

int bp=s.nextInt();

int hra=0;

int da=0;

int g=0;

if(bp<=10000)

hra=(bp*20)/100;
da=(bp*80)/100;

g=bp+hra+da;

System.out.println("gross salary"+g+" "+hra+" "+da);

else if(bp<=20000)

hra=(bp*25)/100;

da=(bp*90)/100;

g=bp+hra+da;

System.out.println("gross salary"+g+" "+hra+" "+da);

else if(bp>20000)

if(bp<=10000)

hra=(bp*30)/100;

da=(bp*95)/100;

g=bp+hra+da;

System.out.println("gross salary"+g+" "+hra+" "+da);

10000

gross salary20000 2000 8000

6.

import java.util.*;

public class Main

public static void main(String[] args) {


Scanner s=new Scanner(System.in);

int a=s.nextInt();

int d=0;

if(a<100)

System.out.println("your bill is:"+a);

else{

d=(a*10)/100;

a=a-d;

System.out.println("Your bill is"+a);

200

Your bill is 180

9. import java.util.*;

public class Main

public static void main(String[] args) {

Scanner sc=new Scanner(System.in);

int n=sc.nextInt();

int count=0,s=n;

while(n!=0)

count+=1;

n=n/10;

System.out.println("Number of digits in "+s+" is : "+count);

}
}

Number of digit in 10000 is :5

You might also like