Here is a calculator to find how many more days your birthday is in, but when you enter a day that is before today's date, then the calculator will not give you the correct answer. I cannot use import.calender, so how would I solve the problem so that if the birthday was before the date entered that it would give me the correct number of days?
import java.util.Scanner;
public class Birthdays {
public static void main(String[] args) {
Scanner newscanner = new Scanner(System.in);
System.out.print("Please enter today's date (month day): ");
int z = newscanner.nextInt();
int y = newscanner.nextInt();
System.out.println("Today is " + z + "/" + y + "/2016, day #" + absoluteDay(z, y) + " of the year");
System.out.println();
System.out.print("Please enter person #1's birthday (month day): ");
int j = newscanner.nextInt();
int k = newscanner.nextInt();
System.out.println(j + "/" + k + "/2016. Your next birthday is in "
+ (Math.abs(absoluteDay(z, y) - absoluteDaytwo(j, k))) + " day(s)");
System.out.println();
System.out.print("Please enter person #2's birthday (month day): ");
int q = newscanner.nextInt();
int w = newscanner.nextInt();
System.out.println(q + "/" + w + "/2016. Your next birthday is in "
+ (Math.abs(absoluteDay(z, y) - absoluteDaythree(q, w))) + " day(s)");
if (j + k > q + w) {
System.out.print("Person #1's birthday is sooner.");
} else {
System.out.print("Person #2's birthday is sooner.");
}
}
public static int absoluteDay(int z, int y) {
if (z == 1)
return y;
if (z == 2)
return y + 31;
if (z == 3)
return y + 60;
if (z == 4)
return y + 91;
if (z == 5)
return y + 121;
if (z == 6)
return y + 152;
if (z == 7)
return y + 182;
if (z == 8)
return y + 213;
if (z == 9)
return y + 244;
if (z == 10)
return y + 274;
if (z == 11)
return y + 305;
if (z == 12)
return y + 335;
else
return 0;
}
public static int absoluteDaytwo(int q, int w) {
if (q == 1)
return w;
if (q == 2)
return w + 31;
if (q == 3)
return w + 60;
if (q == 4)
return w + 91;
if (q == 5)
return w + 121;
if (q == 6)
return w + 152;
if (q == 7)
return w + 182;
if (q == 8)
return w + 213;
if (q == 9)
return w + 244;
if (q == 10)
return w + 274;
if (q == 11)
return w + 305;
if (q == 12)
return w + 335;
else
return 0;
}
public static int absoluteDaythree(int j, int k) {
if (j == 1)
return k;
if (j == 2)
return k + 31;
if (j == 3)
return k + 60;
if (j == 4)
return k + 91;
if (j == 5)
return k + 121;
if (j == 6)
return k + 152;
if (j == 7)
return k + 182;
if (j == 8)
return k + 213;
if (j == 9)
return k + 244;
if (j == 10)
return k + 274;
if (j == 11)
return k + 305;
if (j == 12)
return k + 335;
else
return 0;
}
}
the key point is very simple,
if (today > birthday) then
nextBirthday = 365 - (today-birthday)
Here is the complete code:
/**
* Created by chenzhongpu on 23/10/2015.
*/
import java.util.Scanner;
public class Birthdays {
private static int DAYS_YEAR = 365;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Please enter today's date (month day): ");
int z = scanner.nextInt();
int y = scanner.nextInt();
int currentDays = absoluteDay(z, y);
System.out.println("Today is " + z + "/" + y + "/2016, day #" + currentDays + " of the year");
System.out.print("Please enter person #1's birthday (month day): ");
int j = scanner.nextInt();
int k = scanner.nextInt();
int birthDayDays1 = absoluteDay(j, k);
int nextBirthdays1 =
birthDayDays1-currentDays >= 0 ? birthDayDays1-currentDays: DAYS_YEAR - (currentDays-birthDayDays1);
System.out.println(j + "/" + k + "/2016. Your next birthday is in "
+ nextBirthdays1 + " day(s)");
System.out.print("Please enter person #2's birthday (month day): ");
int q = scanner.nextInt();
int w = scanner.nextInt();
int birthDayDays2 = absoluteDay(q, w);
int nextBirthdays2 =
birthDayDays2-currentDays >= 0 ? birthDayDays2-currentDays: DAYS_YEAR - (currentDays-birthDayDays2);
System.out.println(q + "/" + w + "/2016. Your next birthday is in "
+ nextBirthdays2 + " day(s)");
if(nextBirthdays1 > nextBirthdays2){
System.out.println("#2 is sooner");
}else if(nextBirthdays1 < nextBirthdays2){
System.out.println("#1 is sooner");
}else{
System.out.println("equal");
}
}
private static int absoluteDay(int month, int day){
int[] days = {0, 0, 31, 60, 91, 121, 91, 121, 152, 182,
213, 244, 274, 305, 335};
return days[month] + day;
}
}
Related
I am making a dice game, the rules are 2 dice are thrown randomly, if the sum of both dice are 7 or 11 in the first try, the user wins. if the sum is 2,3 or 12 in the first try, the user loses. if the sum is 4,5,6,8,9,10 then that sum is set as an establish point and continues to throw the dice till the sum matches the established point and the user wins, however if the establish point is 7 the user loses.
the game plays 3 times and records how many times I have won or lost. however, I am not able to get that part finished, help would be appreciated, my code is bellow.
package roll;
import java.util.Random;
public class RandomSumGame {
boolean start;
int d1;
int d2;
int sum = d1 + d2;
int valuepoint;
String plus = "+";
public void play(int d1, int d2) {
int win = 0;
int loss = 0;
sum = d1 + d2;
for (;;) {
if (sum == 2 || sum == 3 || sum == 12) {
start = false;
loss++;
System.out.println(" = " + sum + ";you lose");
break;
} else if (sum == 7 || sum == 11) {
start = true;
win++;
System.out.println(" = " + sum + ";you win ");
break;
}
valuepoint = sum;
if (valuepoint == 4 || valuepoint == 5 || valuepoint == 6 || valuepoint == 8 || valuepoint == 9
|| valuepoint == 10) {
System.out.print(" = " + valuepoint + " you establish a value point " + valuepoint + "\n");
break;
}
}
for (;;) {
if (sum == 7 || sum == 11) {
break;
} else {
Random rand = new Random();
for (int i = 0; i < 1; i++) {
d1 = 1 + rand.nextInt(6);
int f1 = d1;
System.out.print("\t" + "-you rolled again " + d1 + " " + plus);
for (int x = 0; x < 1; x++) {
d2 = 1 + rand.nextInt(6);
int f2 = d2;
int loda = f1 + f2;
System.out.print(" " + d2 + " = " + loda + "\n");
}
}
sum = d1 + d2;
if (sum == valuepoint) {
start = true;
win++;
System.out.print("\t" + "you win!" + "\n");
break;
} else if (sum == 7) {
loss++;
start = false;
System.out.print("\t" + "you lose " + "\n");
break;
}
}
}
System.out.print("wins: " + win + "\n");
System.out.print("Losses:" + loss);
}
public void play() {
for (int x = 0; x < 3; x++) {
rolldice();
play(d1, d2);
System.out.print("\n");
}
}
public void rolldice() {
Random rand = new Random();
for (int i = 0; i < 1; i++) {
d1 = 1 + rand.nextInt(6);
System.out.print("You rolled " + d1 + " " + plus);
}
for (int i = 0; i < 1; i++) {
d2 = 1 + rand.nextInt(6);
System.out.print(" " + d2 + " ");
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
RandomSumGame Teet = new RandomSumGame();
RandomSumGame d1counter = new RandomSumGame();
RandomSumGame d2counter = new RandomSumGame();
Teet.play();
}
}
What part are you not able to finish? Seems like the game is running 3 times? Is it the total number of wins and loses? To fix that, you could just move "int win" and "int lose" outside the play method to make them global variables.
EDIT:
If you don't want to use global variables, you could make a method that calls itself (recursive method)
import java.util.Random;
public class RandomSumGame {
boolean start;
int d1;
int d2;
int sum = d1 + d2;
int valuepoint;
String plus = "+";
public void play(int d1, int d2, int win, int loss) {
sum = d1 + d2;
for (;;) {
if (sum == 2 || sum == 3 || sum == 12) {
start = false;
loss++;
System.out.println(" = " + sum + ";you lose");
break;
} else if (sum == 7 || sum == 11) {
start = true;
win++;
System.out.println(" = " + sum + ";you win ");
break;
}
valuepoint = sum;
if (valuepoint == 4 || valuepoint == 5 || valuepoint == 6 || valuepoint == 8 || valuepoint == 9
|| valuepoint == 10) {
System.out.print(" = " + valuepoint + " you establish a value point " + valuepoint + "\n");
break;
}
}
for (;;) {
if (sum == 7 || sum == 11) {
break;
} else {
Random rand = new Random();
for (int i = 0; i < 1; i++) {
d1 = 1 + rand.nextInt(6);
int f1 = d1;
System.out.print("\t" + "-you rolled again " + d1 + " " + plus);
for (int x = 0; x < 1; x++) {
d2 = 1 + rand.nextInt(6);
int f2 = d2;
int loda = f1 + f2;
System.out.print(" " + d2 + " = " + loda + "\n");
}
}
sum = d1 + d2;
if (sum == valuepoint) {
start = true;
win++;
System.out.print("\t" + "you win!" + "\n");
break;
} else if (sum == 7) {
loss++;
start = false;
System.out.print("\t" + "you lose " + "\n");
break;
}
}
}
System.out.print("wins: " + win + "\n");
System.out.print("Losses:" + loss);
if (win < 2 && loss < 2) {
System.out.print("\n");
//Recursive
play(win, loss);
}
}
public void play(int win, int loss) {
rolldice();
play(d1, d2, win, loss);
}
public void rolldice() {
Random rand = new Random();
for (int i = 0; i < 1; i++) {
d1 = 1 + rand.nextInt(6);
System.out.print("You rolled " + d1 + " " + plus);
}
for (int i = 0; i < 1; i++) {
d2 = 1 + rand.nextInt(6);
System.out.print(" " + d2 + " ");
}
}
public static void main(String[] args) {
RandomSumGame test = new RandomSumGame();
test.play(0,0);
}
}
I want the output to be something like "6 + 6 + 6 + 6 = 24" but seeing as how the System.out.print(x + " + ") is inside the recursive loop, it ends up outputting: "6 + 6 + 6 + 6 + = 24"
In the main program I have a separate line of code to output the result:
System.out.print("= " + result);
public static int recursiveMultiply(int x, int y){
//Make y positive
if(y < 0)
return recursiveMultiply(-x, -y);
//base case
if(y == 0)
return 0;
//recursive case
System.out.print(x + " + ");
return x + recursiveMultiply(x, y-1);
As the first 2 conditions, a if(y>=1) is useless
public static int recursiveMultiply(int x, int y) {
if (y < 0) {
return recursiveMultiply(-x, -y);
}
if (y == 0) {
return 0;
}
System.out.print(x);
if (y != 1) {
System.out.print(" + ");
}
return x + recursiveMultiply(x, y - 1);
}
public static void main(String[] args) {
System.out.println("="+ recursiveMultiply(-6,-4));
}
private static int recursiveMultiply(int i, int j) {
if (j< 0) {
return recursiveMultiply(i, Math.abs(-j));
}
if (j == 0) {
return 0;
}
System.out.print(i);
if (j!= 1) {
System.out.print(" + ");
}
return i + recursiveMultiply(i, j - 1);
}
I am trying to write a program where the user inputs 2 dates and the program calculates the days in between (without using any of the calendar classes) and prints the results, but I keep getting crazy numbers that make no sense. When I tried to make it calculate 5 days it printed the results of 333 and when I try to do something like 20 years it prints numbers in the millions.
import java.util.Scanner;
public class DaysCalc {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.print("Please enter starting date (mm-dd-yyyy) ");
String startingdate = input.next();
System.out.print("Please enter ending date (mm-dd-yyyy) ");
String finishingdate = input.next();
String startingdayst = startingdate.substring(3, 5);
String startingmonthst = startingdate.substring(0, 2);
String startingyearst = startingdate.substring(6, 10);
String finishingdayst = finishingdate.substring(3, 5);
String finishingmonthst = finishingdate.substring(0, 2);
String finishingyearst = finishingdate.substring(6, 10);
int startingyear = Integer.parseInt(startingyearst);
int startingday = Integer.parseInt(startingdayst);
int startingmonth = Integer.parseInt(startingmonthst);
int finishingyear = Integer.parseInt(finishingyearst);
int finishingday = Integer.parseInt(finishingdayst);
int finishingmonth = Integer.parseInt(finishingmonthst);
System.out.println(startingyear + "," + startingday + "," + startingmonth );
System.out.println(finishingyear + "," + finishingday + "," + finishingmonth);
int daysLeft = 0;
int daysUntilEnd = 0;
int i = 0;
daysLeft = daysInAMonth(startingmonth, startingyear) - startingday;
daysUntilEnd = finishingday;
for (int monthCount = startingmonth + 1; monthCount <= 12; monthCount++)
{
i += daysInAMonth(monthCount, startingyear);
}
for (int yearCount = startingyear + 1; yearCount <= finishingyear; yearCount++)
{
if (isLeapYear(yearCount))
{
i = i * 366;
}
else
{
i = i * 365;
}
i += daysUntilEnd;
}
System.out.println(i);
}
private static boolean isLeapYear(int year) {
boolean isLeapYear = ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0));
return isLeapYear;
}
private static int daysInAMonth(int month, int year) {
if (month == 2)
{
if (isLeapYear(year) )
{
return 29;
}
else
{
return 28;
}
}
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 9 || month == 11) {
return 31;
}
return 30;
}
}
the problem was with this part
for (int monthCount = startingmonth + 1; monthCount < finishingmonth; monthCount++)
{
i += daysInAMonth(monthCount, startingyear);
}
for (int yearCount = startingyear + 1; yearCount <= finishingyear; yearCount++)
{
if (isLeapYear(yearCount))
{
i = i + 366;
}
else
{
i = i + 365;
}
}
i += daysUntilEnd;
i += daysInAMonth(startingmonth, startingyear)-startingday-1;
System.out.println(i);
it's not completely bug free but i hope it helps you to see where it went wrong. it was kind of an eye mistake
Hi guys i really need your help. I need to output a 3 year calendar in 3 columns. In the first column the year should be the year that the user input.
I have a code that will post a 3 year calendar but only in 1 column. I need to separate the other year in another column plss help me
package project;
import java.util.*;
public class les1 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
Calendar cal = Calendar.getInstance();
String ans;
// getting the system calendar's year, maximum days,
// weeks per month and system calendar's month.
int year = cal.get(Calendar.YEAR);
int day = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
int week = cal.get(Calendar.DAY_OF_WEEK);
int month = cal.get(Calendar.MONTH);
int col[] = new int[3];
do {
// validation for input year
do {
System.out.print("\nEnter year: ");
while (true)
try {
year = Integer.parseInt(in.next());
break;
} catch (Exception ex) {
System.out.println("Try again!");
System.out.print("\nEnter year: ");
}
if (year < 1900 || year > 2099) {
System.out.println("Try again!");
}
} while (year < 1900 || year > 2099);
/*
* System.out.println("enter number of elements");
*
* int n = in.nextInt();
*
* int arr[] = new int[n];
*
* for (int j = 0; j < n; j++) {// for reading array
*
* }
*
* for (int j : arr) {
*/
// loop for months
for (month = 1; month <= 1; month++) {
// calculating years, month, days and weeks.
int y = year - (14 - month) / 12;
int x = y + y / 4 - y / 100 + y / 400;
int m = month + 12 * ((14 - month) / 12) - 2;
int d = (1 + x + (31 * m) / 12) % 7;
// calculate leap year
boolean LeapYear = (year % 400 == 0);
// displaying month as String
cal.set(year, month, 0);
System.out
.print(cal.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.ENGLISH) + "\t\t\t\t\t\t");
System.out.print("Sun Mon Tue Wed Thu Fri Sat" + "\t\t\t");
int length = (int) (30 + ((month + (month / 8.0)) % 2));
if (month == 2) {
if (LeapYear) {
length -= 1;
} else {
length -= 2;
}
}
for (int a = 0; a < col.length; a++) {
int counter = 1;
// spacing for first day of the month
for (int i = 0; i < d; i++) {
System.out.print(" ");
counter++;
}
// spacing for days
for (day = 1; day <= length; day++) {
System.out.printf("%2d", day);
System.out.print((counter++ % 7 != 0) ? " " : "\n");
}
}
week = (week + length) % 6;
}
year++;
/* } */
System.out.print("\n\n" + "Enter another year (Y/N)? ");
ans = in.next();
} while (ans.equals("Y") || ans.equals("y"));
System.out.println("\nEnd!");
in.close();
}
}
Take a look at the following code. It will print three different years' calendars in three columns. I have used this formula to determine the day of the week in any month.
import java.util.*;
public class les1 {
public static void main(String[] args) {
String[] days = {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
};
Scanner in = new Scanner(System. in );
Calendar cal = Calendar.getInstance();
String ans;
int year = cal.get(Calendar.YEAR);
int day = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
int week = cal.get(Calendar.DAY_OF_WEEK);
int month = cal.get(Calendar.MONTH);
int col[] = new int[3];
do {
// validation for input year
do {
System.out.print("\nEnter year: ");
while (true)
try {
year = Integer.parseInt( in .next());
break;
} catch (Exception ex) {
System.out.println("Try again!");
System.out.print("\nEnter year: ");
}
if (year < 1900 || year > 2099) {
System.out.println("Try again!");
}
} while (year < 1900 || year > 2099);
for (month = 1; month <= 1; month++) {
HashMap < Integer, Integer > map = new HashMap < Integer, Integer > ();
map.put(1, 0);
map.put(7, 6);
map.put(2, 3);
map.put(8, 2);
map.put(3, 3);
map.put(9, 5);
map.put(4, 6);
map.put(10, 0);
map.put(5, 1);
map.put(11, 3);
map.put(6, 4);
map.put(12, 5);
System.out.println();
for (int a = 0; a < col.length; a++) {
int counter = 1;
System.out.printf("%-6s%-6s%-6s%-6s%-6s%-6s%-6s", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
System.out.printf("\t\t\t"); //Formatting for days
}
// System.out.println();
// calculate leap year
boolean LeapYear = false;
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) LeapYear = true;
// displaying month as String
ArrayList < Integer > dds = new ArrayList < Integer > ();
dds.add(0);
dds.add(0);
dds.add(0);
dds.add(0);
int indexofA = 0;
String yy = year + "";
int m;
if (LeapYear && month == 1) m = map.get(month) + 6;
else if (LeapYear && month == 2) m = map.get(month) - 1;
else m = map.get(month);
int y = Integer.parseInt(yy.substring(2, 4));
int c = (year / 100);
if (c % 4 == 0) c = 6;
else if (c % 4 == 1) c = 4;
else if (c % 4 == 2) c = 2;
else c = 0;
int x = y + y / 4 + c;
int d = (1 + x + m) % 7;
// cal.set(year, month, 0);
int length = (int)(30 + ((month + (month / 8.0)) % 2));
if (month == 2) {
if (LeapYear) {
length -= 1;
} else {
length -= 2;
}
}
System.out.print("len : " + length);
System.out.println();
boolean thirtyone = false;
int count = 0;
for (int r = 0; r < 6; r++) { //For each row of the calendars
String[] dayss = new String[7];
int index = 0;
for (int a = 0; a < col.length; a++) { //For each column of a calendar
for (int i = 0; i < d && dds.get(indexofA) == 0; i++) {
dayss[index] = " ";
index++;
}
for (day = dds.get(indexofA) + 1; day <= length; day++) {
if (day == 31) {
dayss[index] = day + "";
index++;
thirtyone = true;
} else if (day < 31) {
dayss[index] = day + "";
index++;
}
if (index == 7) {
dds.set(indexofA, day);
break;
}
}
indexofA++;
System.out.printf("%-6s%-6s%-6s%-6s%-6s%-6s%-6s", dayss[0], dayss[1], dayss[2], dayss[3],
dayss[4], dayss[5], dayss[6]);
System.out.printf("\t\t\t");
index = 0;
year++;
LeapYear = false;
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) LeapYear = true;
yy = year + "";
if (LeapYear && month == 1) m = map.get(month) + 6;
else if (LeapYear && month == 2) m = map.get(month) - 1;
else m = map.get(month);
y = Integer.parseInt(yy.substring(2, 4));
c = (year / 100);
if (c % 4 == 0) c = 6;
else if (c % 4 == 1) c = 4;
else if (c % 4 == 2) c = 2;
else c = 0;
x = y + y / 4 + c;
d = (1 + x + m) % 7;
}
year -= 3;
yy = year + "";
LeapYear = false;
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) LeapYear = true;
if (LeapYear && month == 1) m = map.get(month) + 6;
else if (LeapYear && month == 2) m = map.get(month) - 1;
else m = map.get(month);
y = Integer.parseInt(yy.substring(2, 4));
c = (year / 100);
if (c % 4 == 0) c = 6;
else if (c % 4 == 1) c = 4;
else if (c % 4 == 2) c = 2;
else c = 0;
x = y + y / 4 + c;
d = (1 + x + m) % 7;
indexofA = 0;
System.out.println();
}
}
System.out.print("\n\n" + "Enter another year (Y/N)? ");
ans = in .next();
} while (ans.equals("Y") || ans.equals("y"));
System.out.println("\nEnd!"); in .close();
}
}
error: ';' expected
illegal start of expression
These are the two errors im getting within the program on both getGrid and checkGrid
Cannot seem to figure out what the problem is and what is causing it.
help would be appreciated
import java.util.Scanner;
public class Aleko_SudokuChecker
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print("\nWelcome to the Sudoku Checker v1.0!\n");
System.out.print("\nThis program checks simple, small, 4x4 Sudoku grids for\n");
System.out.print("correctness. Each column, row and 2x2 region contains the numbers\n");
System.out.print("1 through 4 only once.\n\n");
System.out.print("To check your sudoku, enter your board one row at a time, with\neach digit separated by a space. Hit ENTER at the end of a row.\n");
SudokuChecker foo = new SudokuChecker();
foo.getGrid();
foo.checkGrid();
public void getGrid()
{
System.out.print("\nEnter Row 1: ");
int i = in.nextInt();
int j = in.nextInt();
int k = in.nextInt();
int m = in.nextInt();
System.out.print("Enter Row 2: ");
int n = in.nextInt();
int i1 = in.nextInt();
int i2 = in.nextInt();
int i3 = in.nextInt();
System.out.print("Enter Row 3: ");
int i4 = in.nextInt();
int i5 = in.nextInt();
int i6 = in.nextInt();
int i7 = in.nextInt();
System.out.print("Enter Row 4: ");
int i8 = in.nextInt();
int i9 = in.nextInt();
int i10 = in.nextInt();
int i11 = in.nextInt();
}
public void checkGrid()
{
System.out.print("\nThank you. Now checking ... \n");
int x = 0;
int i12 = i + j + n + i1;
int i13 = i4 + i5 + i8 + i9;
int i14 = k + m + i2 + i3;
int i15 = i6 + i7 + i10 + i11;
int i16 = i + j + k + m;
int i17 = n + i1 + i2 + i3;
int i18 = i4 + i5 + i6 + i7;
int i19 = i8 + i9 + i10 + i11;
int i20 = i + n + i4 + i8;
int i21 = j + i1 + i5 + i9;
int i22 = k + i2 + i6 + i10;
int i23 = m + i3 + i7 + i11;
if (i12 == 10)
{
System.out.print("\nREG-1:PASS");
}
else
{
System.out.print("\nREG-1:FAIL");
x = x+1;
}
if (i13 == 10)
{
System.out.print("\nREG-2:PASS");
}
else
{
System.out.print("\nReg-2:FAIL");
x = x +1;
}
if (i14 == 10)
{
System.out.print("\nREG-3:PASS");
}
else
{
System.out.print("\nREG-3:FAIL");
x = x+1;
}
if (i15 == 10)
{
System.out.print("\nREG-4:PASS\n");
}
else
{
System.out.print("\nREG-4:FAIL\n");
x = x+1;
}
if (i16 == 10)
{
System.out.print("\nROW-1:PASS");
}
else
{
System.out.print("\nROW-1:FAIL");
x = x+1;
}
if (i17 == 10)
{
System.out.print("\nROW-2:PASS");
}
else
{
System.out.print("\nROW-2:FAIL");
x = x+1;
}
if(i18 == 10)
{
System.out.print("\nROW-3:PASS");
}
else
{
System.out.print("\nROW-3:FAIL");
x = x+1;
}
if (i19 == 10)
{
System.out.print("\nROW-4:PASS\n");
}
else
{
System.out.print("\nROW-4:FAIL\n");
x = x+1;
}
if (i20 == 10)
{
System.out.print("\nCOL-1:PASS");
}
else
{
System.out.print("\nCOL-1:FAIL");
x = x+1;
}
if (i21 == 10)
{
System.out.print("\nCOL-2:PASS");
}
else
{
System.out.print("\nCOL-2:FAIL");
x = x+1;
}
if (i22 == 10)
{
System.out.print("\nCOL-3:PASS");
}
else
{
System.out.print("\nCOL-3:FAIL");
x = x+1;
}
if (i23 == 10)
{
System.out.print("\nCOL-4:PASS\n");
}
else
{
System.out.print("\nCOL-4:FAIL\n");
x = x+1;
}
if ((i12 == 10) && (i13 == 10) && (i14 == 10) && (i15 == 10) && (i16 == 10) && (i17 == 10) && (i18 == 10) && (i19 == 10) && (i20 == 10) && (i21 == 10) && (i22 == 10) && (i23 == 10)) {
System.out.print("\nCongratulations!\nThis Sudoku is valid.\n\n");
}
else
{
System.out.print("\nSorry.\nThis Sudoku is invalid.\n\n");
}
}
}
}
I think you need to close the main() method with a brace "}" after foo.checkGrid(); and before you start the new method public void getGrid().