java practical 3 (Given two non-negative int values, return true if they have the same first digit, such as with 72 and 75. firstDigit(7, 71) → true firstDigit(6, 17) → false firstDigit(31, 311) → true )
AIM: Given two non-negative int values,
return true if they have the same first digit, such as with 72 and 75.
firstDigit(7, 71) → true firstDigit(6, 17) → false
firstDigit(31, 311) → true
import java.util.*;
class Cal{
static boolean firstDigit(int a, int b)
{
while(a>=10)
a/=10;
while(b>=10)
b/=10;
if(a==b)
return true;
else
return false;
}
}
public class Three {
public static void main(String[] args) {
int a,b;
char response='n';
Scanner in=new Scanner(System.in);
do{
System.out.print("Enter Two Digits: ");
a=in.nextInt();
b=in.nextInt();
boolean ans=Calculation.firstDigit(a,b);
System.out.println("Answer:"+ans);
System.out.println("If You want to continue press (y) ,else press
(n)");
response=in.next().charAt(0);
}while(response=='y');
System.out.println("\nPrepared By: 19CE112 PIPARIYA PREYASH");
}
}
No comments: