Though the problem seemed simple, here it is :-
A Kaprekar number is a positive whole number n with d digits, such that when we split its square into two pieces - a right hand piece r with d digits and a left hand piece l that contains the remaining d or d−1 digits, the sum of the pieces is equal to the original number (i.e. l + r = n).
The Task
You are given the two positive integers p and q, where p is lower than q. Write a program to determine how many Kaprekar numbers are there in the range between p and q (both inclusive) and display them all.
Input Format
There will be two lines of input: p, lowest value q, highest value
Constraints:
0<p<q<100000
Output Format
Output each Kaprekar number in the given range, space-separated on a single line. If no Kaprekar numbers exist in the given range, print INVALID RANGE.
I could not clear the test cases in the range
22223
99999
In the above range the follwoing numbers should have been generated :-
77778 82656 95121 99999
Here is my code :-
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner scan = new Scanner(System.in);
int p = scan.nextInt();
int q = scan.nextInt();
boolean exist = false;
if(q <= p){
System.out.println("INVALID RANGE");
}
int m = 0,n = 0;
long sqr = 0;
String numb = "";
String[] digits = new String[2];
for(int i = p; i <= q; i++){
if(i == 1)System.out.print(1 + " ");
else{
sqr = i*i;
numb = String.valueOf(sqr);// Changing it into a string.
if(numb.length() % 2 == 0){
digits[0] = numb.substring(0, numb.length()/2);//Splitting it into two parts
digits[1] = numb.substring(numb.length()/2);
}else{
digits[0] = numb.substring(0, (numb.length() - 1)/2);
digits[1] = numb.substring((numb.length() -1)/2);
}
if(digits[0] == "" )
m = 0;
if(digits[1] == "")
n = 0;
if(!digits[1].equals("") && !digits[0].equals("")){
m = Integer.parseInt(digits[0]);
n = Integer.parseInt(digits[1]);
}
if(i == (m + n) ){ //Testing for equality
System.out.print(i + " ");
exist = true;
}
}
}
if(exist == false){// If exist is never modified print Invalid Range.
System.out.println("INVALID RANGE");
}
}
}
import java.util.*;
public class Kaprekar
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number");
int num=sc.nextInt();
int sq=num*num; String sq1=Integer.toString(sq);
int mid=(Integer.toString(sq).length())/2;
int rem=sq%((int)Math.pow(10,sq1.length()-mid));
int quo=sq/((int)Math.pow(10,sq1.length()-mid));
int sum=rem+quo;
if(sum==num)
{System.out.println("Kaprekar");}else{System.out.println("Not Kaprecar");}
}
}
Changing the type of Loop index i from int to long fixed the problem.
The square computation of i*i was overflowing the upper limit of int so by changing it to long we were able to get the required computation done.
Thanks to Rup for pointing this out.
The code which cleared all the test cases is here :-
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner scan = new Scanner(System.in);
int p = scan.nextInt();
int q = scan.nextInt();
boolean exist = false;
if(q <= p){
System.out.println("INVALID RANGE");
return;
}
int m = 0,n = 0;
long sqr = 0;
String numb = "";
String[] digits = new String[2];
for(long i = p; i <= q; i++){
if(i == 1)System.out.print(1 + " ");
else{
sqr = i*i;
numb = String.valueOf(sqr);
if(numb.length() % 2 == 0){
digits[0] = numb.substring(0, numb.length()/2);
digits[1] = numb.substring(numb.length()/2);
}else{
digits[0] = numb.substring(0, (numb.length() - 1)/2);
digits[1] = numb.substring((numb.length() -1)/2);
}
if(digits[0] == "" )
m = 0;
if(digits[1] == "")
n = 0;
if(!digits[1].equals("") && !digits[0].equals("")){
m = Integer.parseInt(digits[0]);
n = Integer.parseInt(digits[1]);
}
if(i == (m + n) ){
System.out.print(i + " ");
exist = true;
}
}
}
if(exist == false){
System.out.println("INVALID RANGE");
}
}
}
import java.io.*;
import java.math.*;
import java.util.*;
class Kaprekar {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int p = scanner.nextInt();
int q = scanner.nextInt();
long i,n,s,a,c,k,d,e=0;
for(i=p;i<=q;i++)
{
k=i;d=0;
while(k!=0)
{
d++;
k=k/10;
}
c=0;s=0;n=i*i;
while(n!=0)
{
a=n%10;
n=n/10;
s=s+ (int)Math.pow(10,c)*a;
c++;
if(n+s==i&&(c==d||c==d-1)&&s!=0)
{
System.out.print(i+" ");
e++; break;
}
}
}
if(e==0)
{
System.out.println("INVALID RANGE");
}
scanner.close();
}
}
Related
import java.lang.Math;
import javax.swing.JOptionPane;
public class IntegerNumber
{
//declaring main variable used throughout the whole code
public static void main(String[] args)
{
//declare variable
int menuNumber;
String input = JOptionPane.showInputDialog("Select What You want to do: \n1: Calculate the total of the squares of the first inputted natural numbers. \n 2: Get the mean of the first N odd natural numbers. \n 3: Determine if the inputted number is a prime number. \n 4: Return a Fibonacci number. \n 5: Exit Program.");
menuNumber = Integer.parseInt(input);
if (menuNumber == 1)
{
TotalSquares();
}
else if (menuNumber == 2)
{
OddNumberMean();
}
else if (menuNumber == 3)
{
PrimeNumber();
}
else if (menuNumber == 4)
{
FibonacciNumber();
}
else if (menuNumber == 5)
{
System.exit(0);
}
}
public static double TotalSquares()
{
int N;
double total;
int k;
String input = JOptionPane.showInputDialog("Enter a number between 1 and 20 to find the total squared numbers of");
N = Integer.parseInt(input);
total = 0;
for(k=1; k<=N; k++);
total +=(k*k);
return total;
System.out.println("Your total is = " + total);
}
public static double OddNumberMean()
{
int N;
int i;
String input = JOptionPane.showInputDialog("Enter a number between 1 and 50 to find the mean of the odd numbers");
N = Integer.parseInt(input);
double total = 0;
for(i=0;i<=N; i++);
{ total+= 2*i +1;};
System.out.println("The mean is = " + (total/N));
}
public static double PrimeNumber()
{
int N;
int g;
String input = JOptionPane.showInputDialog("Enter a number between 2 and 200, determine whether or not the number is prime");
N = Integer.parseInt(input);
for (g = 2; g<N; g++)
{
if (N % g == 0)
{
System.out.println("The number is not prime");
}
}
System.out.println("The number is prime");
}
public static int FibonacciNumber(int N)
{
String input = JOptionPane.showInputDialog("Compute and return a Fibonacci number");
N = Integer.parseInt(input);
if (N==0)
return 0;
else if(N==1)
return 1;
else
return FibonacciNumber(N-1) + FibonacciNumber(N-2);
}
}
I keep getting this error:
IntegerNumber.java:33: error: method FibonacciNumber in class
IntegerNumber cannot be applied to given types;
FibonacciNumber();
^ required: int found: no arguments reason: actual and formal
argument lists differ in length
and I can not find a way to fix it. Any help appreciated as I can't seem to find the answer on other posts.
Replace
public static int FibonacciNumber(int N)
{
...
N = Integer.parseInt(input);
with
public static int FibonacciNumber()
{
...
int N = Integer.parseInt(input);
You called FibonacciNumber() without parameters, whereas the original method declaration wanted a parameter int N.
Furthermore for methods, fields and variables use an initial small letter: fibonacciNumber, n.
I have a program that prompts the user for a string, an initial base, and a final base. The program works fine for all digits however, when I enter in a string mixed with digits and characters it does not return the correct answer. For example, when I input the string BDRS7OPK48DAC9TDT4, original base: 30, newBase: 36, it should return ILOVEADVANCEDJAVA, but instead I get ILOVEADVANHSC6LTS. I know it's a problem with my algorithm but I cant figure out why it's returning the incorrect conversion.
import java.util.Scanner;
public class BaseConversion {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
String theValue;
String result;
String newNum;
int initialBase;
int finalBase;
String[] parts = args;
if (parts.length > 0) {
theValue = parts[0];
isValidInteger(theValue);
initialBase = Integer.parseInt(parts[1]);
finalBase= Integer.parseInt(parts[2]);
isValidBase(finalBase);
}
else {
System.out.println("Please enter a value: ");
theValue = s.nextLine();
isValidInteger(theValue);
System.out.println("Please enter original base: ");
initialBase = s.nextInt();
System.out.println("Please enter new base: ");
finalBase = s.nextInt();
isValidBase(finalBase);
}
// check it
// isValidInteger(theValue, finalBase);
s.close();
newNum = convertInteger(theValue, initialBase, finalBase);
System.out.println("new number: " + newNum);
}
public static void isValidBase(int finalBase) {
if (finalBase < 2 || finalBase > 36) {
System.out.println("Error: Base must be greater than or equal to 2 & less than or equal to 36");
System.exit(1);
}
}
public static void isValidInteger(String num) {
char chDigit;
num = num.toUpperCase();
for(int d = 0; d < num.length(); d++) {
chDigit = num.charAt(d);
if (!Character.isLetter(chDigit) && !Character.isDigit(chDigit)) {
//System.out.println(chDigit);
System.out.println("Error character is not a letter or number");
System.exit(1);
}
}
}
public static String convertInteger(String theValue, int initialBase, int finalBase) {
double val = 0;
double decDigit = 0;
char chDigit;
// loop through each digit of the original number
int L = theValue.length();
for(int p = 0; p < L; p++) {
// get the digit character (0-9, A-Z)
chDigit = Character.toUpperCase(theValue.charAt(L-1-p));
// get the decimal value of our character
if(Character.isLetter(chDigit)) {
decDigit = chDigit - 'A' + 10;
}
else if (Character.isDigit(chDigit)) {
decDigit = chDigit - '0';
}
else {
System.out.println("Error d");
System.exit(1);
}
// add value to total
val += decDigit * Math.pow(initialBase, p);
}
// determine number of digits in new base
int D = 1;
for( ; Math.pow(finalBase, D) <= val; D++) {}
// use char array to hold new digits
char[] newNum = new char[D];
double pwr;
for(int p = D-1; p >= 0; p--) {
// calculate the digit for this power of newBase
pwr = Math.pow(finalBase, p);
decDigit = Math.floor(val / pwr);
val -= decDigit*pwr;
// store the digit character
if(decDigit <= 9) {
newNum[D - 1 - p] = (char) ('0' + (int)decDigit);
}
else {
newNum[D - 1 - p] = (char) ('A' + (int)(decDigit - 10));
}
}
return new String(newNum);
}
}
The algorithm is correct. Take a closer look instead at the place where you convert the input value to a decimal system and in particular at the limitations of the data type you are using.
Resources that could be helpful:
primitive data types - double point in the list
Floating point arithmetic
Question concerning similar problem
JLS - 4.2.3. Floating-Point Types, Formats, and Values
Hope this points you to the right track.
import java.math.BigInteger;
import java.util.Scanner;
public class BaseConversion {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
String theValue;
String result;
String newNum;
int initialBase;
int finalBase;
String[] parts = args;
if (parts.length > 0) {
theValue = parts[0];
isValidInteger(theValue);
initialBase = Integer.parseInt(parts[1]);
finalBase= Integer.parseInt(parts[2]);
isValidBase(finalBase);
}
else {
System.out.println("Please enter a value: ");
theValue = s.nextLine();
isValidInteger(theValue);
System.out.println("Please enter original base: ");
initialBase = s.nextInt();
System.out.println("Please enter new base: ");
finalBase = s.nextInt();
isValidBase(finalBase);
}
// check it
// isValidInteger(theValue, finalBase);
s.close();
newNum = convertInteger(theValue, initialBase, finalBase);
System.out.println("new number: " + newNum);
}
public static void isValidBase(int finalBase) {
if (finalBase < 2 || finalBase > 36) {
System.out.println("Error: Base must be greater than or equal to 2 & less than or equal to 36");
System.exit(1);
}
}
public static void isValidInteger(String num) {
char chDigit;
num = num.toUpperCase();
for(int d = 0; d < num.length(); d++) {
chDigit = num.charAt(d);
if (!Character.isLetter(chDigit) && !Character.isDigit(chDigit)) {
//System.out.println(chDigit);
System.out.println("Error character is not a letter or number");
System.exit(1);
}
}
}
public static String convertInteger(String theValue, int initialBase, int finalBase) {
BigInteger bigInteger = new BigInteger(theValue,initialBase);
String value = bigInteger.toString(finalBase);
value = value.toUpperCase();
return value;
}
}
Here is the correct solution. The problem was with the data type not the algorithm. I hope this helps anyone dealing with the same type of problem.
I'm trying to make code that asks the user to enter 10 numbers and subtracts them all. This is what i have so far. I think i have the general layout all set but i dont know what to do with the rest
import java.util.Scanner;
public class subnumbs
{
int dial;
int[] num = new int [10];
Scanner scan = new Scanner(System.in);
public void go()
{
int q=0;
dial = 10;
while (q != 0)
{
System.out.println("type numb: ");
int newinput = scan.nextInt();
q+=newInteger;
dial = cdial + 1;
}
return q;
}
}
System.out.printIn("Enter Integer: ");
int newInteger = scan.nextLine();
While (newInteger >= 0){
System.out.println("Re-enter Integer (must be negative): ");
newInteger = scan.nextLine();
}
n+=newInteger;
Counter = counter - 1;
return n;
this is one way to ensure inly negative numbers, only count down and add it if it was negative ...
while (counter != 0)
{
System.out.println("Enter Integer: ");
int newInteger = scan.nextInt();
if(newInteger < 0) {
n+=newInteger;
counter -= 1;
}
else {
System.out.println("must be negative integer, please try again: ")
{
}
In general, to ensure an input you have to evaluate it at the point where you are getting the input
I am creating a code that allows you to convert a binary number to a decimal number and vice versa. I have created a code that converts decimal to binary but can not workout how to implement the binary to decimal aspect.
My code for decimal to binary is below:
import java.util.*;
public class decimalToBinaryTest
{
public static void main (String [] args)
{
int n;
Scanner in = new Scanner(System.in);
System.out.println("Enter a positive interger");
n=in.nextInt();
if(n < 0)
{
System.out.println("Not a positive interger");
}
else
{
System.out.print("Convert to binary is: ");
binaryform(n);
}
}
private static Object binaryform(int number)
{
int remainder;
if(number <= 1)
{
System.out.print(number);
return " ";
}
remainder= number % 2;
binaryform(number >> 1);
System.out.print(remainder);
{
return " ";
}
}
}
An explanation to how the binary to decimal code work would help as well.
I have tried the method of the least significant digit*1 then the next least *1*2 then *1*2*2 but can not get it to work.
Thank you #korhner I used your number system with arrays and if statements.
This is my working code:
import java.util.*;
public class binaryToDecimalConvertor
{
public static void main (String [] args)
{
int [] positionNumsArr= {1,2,4,8,16,32,64,128};
int[] numberSplit = new int [8];
Scanner scanNum = new Scanner(System.in);
int count1=0;
int decimalValue=0;
System.out.println("Please enter a positive binary number.(Only 1s and 0s)");
int number = scanNum.nextInt();
while (number > 0)
{
numberSplit[count1]=( number % 10);
if(numberSplit[count1]!=1 && numberSplit[count1] !=0)
{
System.out.println("Was not made of only \"1\" or \"0\" The program will now restart");
main(null);
}
count1++;
number = number / 10;
}
for(int count2 = 0;count2<8;count2++)
{
if(numberSplit[count2]==1)
{
decimalValue=decimalValue+positionNumsArr[count2];
}
}
System.out.print(decimalValue);
}
}
sample:
00000100
0 - 1
0 - 2
1 - 4
0 - 8
0 - 16
0 - 32
0 - 64
0 - 128
Sum values with bit 1 = 4
Good luck!
int decimal = Integer.parseInt("101101101010111", 2);
or if you prefer to doit your self
double output=0;
for(int i=0;i<str.length();i++){
if(str.charAt(i)== '1')
output=output + Math.pow(2,str.length()-1-i);
}
Here is a program which does that.
Make sure the integers you give to int and not too large.
import java.util.Scanner;
public class DecimalBinaryProgram {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (true){
System.out.println("Enter integer in decimal form (or # to quit):");
String s1 = in.nextLine();
if ("#".equalsIgnoreCase(s1.trim())){
break;
}
System.out.println(decimalToBinary(s1));
System.out.println("Enter integer in binary form (or # to quit):");
String s2 = in.nextLine();
if ("#".equalsIgnoreCase(s2.trim())){
break;
}
System.out.println(binaryToDecimal(s2));
}
}
private static String decimalToBinary(String s){
int n = Integer.parseInt(s, 10);
StringBuilder sb = new StringBuilder();
if (n==0) return "0";
int d = 0;
while (n > 0){
d = n % 2;
n /= 2;
sb.append(d);
}
sb = sb.reverse();
return sb.toString();
}
private static String binaryToDecimal(String s){
int degree = 1;
int n = 0;
for (int k=s.length()-1; k>=0; k--){
n += degree * (s.charAt(k) - '0');
degree *= 2;
}
return n + "";
}
}
Of course for this method binaryToDecimal you can just do:
private static String binaryToDecimal(String s){
int n = Integer.parseInt(s, 2);
return n + "";
}
but I wanted to illustrate how you can do that explicitly.
do you want this?
private double dec(String s, int i) {
if (s.length() == 1) return s.equals("1") ? Math.pow(2, i) : 0;
else return (s.equals("1") ? Math.pow(2, i) : 0) + dec(s.substring(0, s.length() - 1), i - 1);
}
dec("101011101",0);
This is a version of a binary to decimal converter. I have used plenty of comments also. Just taught I would like to share it. Hope it is of some use to somebody.
import java.util.Scanner;
public class BinaryToDecimal
{
public static void main(String args[])
{
Scanner input = new Scanner(System.in);
System.out.println("Enter a binary number: ");
String binary = input.nextLine(); // store input from user
int[] powers = new int[16]; // contains powers of 2
int powersIndex = 0; // keep track of the index
int decimal = 0; // will contain decimals
boolean isCorrect = true; // flag if incorrect input
// populate the powers array with powers of 2
for(int i = 0; i < powers.length; i++)
powers[i] = (int) Math.pow(2, i);
for(int i = binary.length() - 1; i >= 0; i--)
{
// if 1 add to decimal to calculate
if(binary.charAt(i) == '1')
decimal = decimal + powers[powersIndex]; // calc the decimal
else if(binary.charAt(i) != '0' & binary.charAt(i) != '1')
{
isCorrect = false; // flag the wrong input
break; // break from loop due to wrong input
} // else if
// keeps track of which power we are on
powersIndex++; // counts from zero up to combat the loop counting down to zero
} // for
if(isCorrect) // print decimal output
System.out.println(binary + " converted to base 10 is: " + decimal);
else // print incorrect input message
System.out.println("Wrong input! It is binary... 0 and 1's like.....!");
} // main
} // BinaryToDecimal
I've written a converter that accepts both strings and ints.
public class Main {
public static void main(String[] args) {
int binInt = 10110111;
String binString = "10110111";
BinaryConverter convertedInt = new BinaryConverter(binInt);
BinaryConverter convertedString = new BinaryConverter(binString);
System.out.println("Binary as an int, to decimal: " + convertedInt.getDecimal());
System.out.println("Binary as a string, to decimal: " + convertedString.getDecimal());
}
}
public class BinaryConverter {
private final int base = 2;
private int binaryInt;
private String binaryString;
private int convertedBinaryInt;
public BinaryConverter(int b) {
binaryInt = b;
convertedBinaryInt = Integer.parseInt(Integer.toString(binaryInt), base);
}
public BinaryConverter(String s) {
binaryString = s;
convertedBinaryInt = Integer.parseInt(binaryString, base);
}
public int getDecimal() {
return convertedBinaryInt;
}
}
public static void main(String[] args)
{
System.out.print("Enter a binary number: ");
Scanner input = new Scanner(System.in);
long num = input.nextLong();
long reverseNum = 0;
int decimal = 0;
int i = 0;
while (num != 0)
{
reverseNum = reverseNum * 10;
reverseNum = num % 10;
decimal = (int) (reverseNum * Math.pow(2, i)) + decimal;
num = num / 10;
i++;
}
System.out.println(decimal);
}
I am making a lottery application in Java. My problem is that I think everything is in place and it (the IDE) is telling me that "int lotteryNumbersCount = Eck_LotteryClass.getLotteryNumbers().length;" needs to be static. So I change it to a static int and then I have to change it again in my class. Problem is when I finally run it I get all 0's for my random lottery data. Please help me find the errors in my ways. Total newb here and I've been looking online here but I want to try to figure it out without just copying code somewhere.
Eck_LotteryClass
import java.util.Random;
public class Eck_LotteryClass {
//instance field
private int lotteryNumbers [];
//Create random lottery numbers method array
public int [] getRandomNumbers(){
lotteryNumbers = new int [5];
Random r = new Random();
for(int i = 0; i < 5; i++)
lotteryNumbers[i] = r.nextInt(10);
return lotteryNumbers;
}
public int compareNumbers(int[] usersNumbers) {
int matchedNums = 0;
if (usersNumbers.length == lotteryNumbers.length) {
for (int i = 0; i < lotteryNumbers.length; i++) {
if (usersNumbers[i] == lotteryNumbers[i]) {
matchedNums ++;
}
}
}
return matchedNums;}
// Display the random lottery numbers for the user
public int [] getLotteryNumbers() {
return lotteryNumbers;
}
}
Eck_LotteryTester
import java.util.Scanner;
import java.util.Arrays;
public class Eck_LotteryTester{
public static void main(String[] args) {
Eck_LotteryClass lottery = new Eck_LotteryClass();
int lotteryNumbersCount = Eck_LotteryClass.getLotteryNumbers().length;
System.out.println("The Pennsylvania Lottery\n");
System.out.println("There are " + lotteryNumbersCount
+ " numbers in my lottery, they are 0 through 9. "
+ "See if you can win big CASH prizes!!!\n");
// Asks the user to enter five numbers.
Scanner keyboard = new Scanner(System.in);
int numbers[] = new int[lotteryNumbersCount];
for (int index = 0; index < numbers.length; index++) {
System.out.print(String.format("Enter Number %d: ", index + 1));
numbers[index] = keyboard.nextInt();
}
// Display the number of digits that match the randomly generated
// lottery numbers.
int match = lottery.compareNumbers(numbers);
if (match == lotteryNumbersCount) {
// If all of the digits match, display a message proclaiming the
// user a grand prize winner.
System.out.println("\nYOU WIN, GO SEE D. LEETE FOR YOUR GRAND PRIZE!!!");
} else {
System.out.println("\nThe winning numbers are " + Arrays.toString(Eck_LotteryClass.getLotteryNumbers()) +
"\nYou matched " + match + " number(s).");
}
}
}
Change
int lotteryNumbersCount = Eck_LotteryClass.getLotteryNumbers().length;
to
int lotteryNumbersCount = lottery .getLotteryNumbers().length;
and you won't have to change the methods signature to static. Also you'll be talking about the same variable.
Also change
// Display the random lottery numbers for the user
public int [] getLotteryNumbers() {
return lotteryNumbers;
}
to
// Display the random lottery numbers for the user
public int [] getLotteryNumbers() {
return getRandomNumbers();
}
So the array gets initialized. And changing the signature of
public int [] getRandomNumbers
to
private int [] getRandomNumbers
wouldn't hurt
package New_list;
import java.util.Scanner;
import java.util.Random;
public class Lottery {
private static Scanner scan;
public static void main(String[] args) {
System.out.println("\t\t\tWelcome to Harsh Lottery System.\n");
Random random = new Random();
int lottery_win_1 = random.nextInt(10);
// Print Lottery winning number...1 :P
// System.out.println(lottery_win_1 + "\n");
int lottery_win_2 = random.nextInt(10);
// Print Lottery winning number...2 :P
// System.out.println(lottery_win_2 + "\n");
boolean loop = true;
while(loop){
System.out.println("\t\t\tEnter your 2 Digit Lottery number.\n");
scan = new Scanner(System.in);
int lottery_no = scan.nextInt();
if ((lottery_no >= 0) && (lottery_no <= 99)) {
int lottery_no_1, lottery_no_2;
if (lottery_no > 9) {
lottery_no_1 = lottery_no / 10;
lottery_no_2 = lottery_no % 10;
} else {
lottery_no_1 = 0;
lottery_no_2 = lottery_no;
}
if ((lottery_win_1 == lottery_no_1)
&& (lottery_win_2 == lottery_no_2)) {
System.out
.println("\t\t\tCongratulation you win lottery,and you win $10000.\n");
} else if ((lottery_win_1 == lottery_no_2)
&& (lottery_win_2 == lottery_no_1)) {
System.out
.println("\t\t\tCongratulation your inverse no is lottery winer number so that you win $4000.\n");
} else if ((lottery_win_1 == lottery_no_1)
|| (lottery_win_1 == lottery_no_2)
|| (lottery_win_2 == lottery_no_1)
|| (lottery_win_2 == lottery_no_2)) {
System.out
.println("\t\t\tCongratulation your one digit from your lotter number match to the lottery winner.so you win $1000.\n");
} else {
System.out.println("\t\t\tSorry,Please try again\n");
System.out.println("\t\t\tDo you want to try again\n\t\t\tPress 1 for Continue\n\t\t\tPress 2 for exit\n");
int ch = scan.nextInt();
switch(ch){
case 1: System.out.println("\t\t\tOk...Try again\n");
break;
case 2: System.out.println("\t\t\tBbye... See you later\n");
loop = false;
break;
}
}
} else {
System.out.println("\t\t\tSorry,Please choose 2 digit number\n");
}
}
}
}