Solved

Get the month to display correctly on this script

Posted on 2004-10-13
9
202 Views
Last Modified: 2010-03-31
Hi, Im trying to display the date correctly in this format: Tuesday, September 26 2004

using this script:

public class ProgramFive {

      public static void main(String[] args) {
            int a;
            int y;
            int m;
            int d;
            int month;
            int day;
            int year;
            String output_s;
            String s = "Sunday   Monday   Tuesday  WednesdayThursday Friday   Saturday ";
            String NameOfTheDayOfTheWeek;
            String g = "January  February March    April    May      June     July     August   SeptemberOctober  November December ";
            String NameOfTheMonth;
            System.out.println("Sebastian Velasquez");
            System.out.println("Please enter a month as an integer, eg: 1 means January, 2 means February.......,12 means december");
            month = ConsoleIn.readLineInt();
            System.out.println("Please enter a day of the month as an integer, eg: 1......31");
            day = ConsoleIn.readLineInt();
            System.out.println("Enter integer year, as 4 digits");
            year = ConsoleIn.readLineInt();
            a = (14 - month) / 12;
            y = year - a;
            m = month + 12 * a;
            d = (day + y + y / 4 - y / 100 + y / 400 + (31 * m) / 12) % 7;
            NameOfTheDayOfTheWeek = s.substring(9 * d, 9 * d + 9);
            NameOfTheMonth = g.substring(9 * m, 9 * m + 9);
            
            
            System.out.println(NameOfTheDayOfTheWeek + ", " + NameOfTheMonth + " " + day + " " + year );
            }
      }
      
I know the problem is on the NameOfTheMonth substring, im just not sure on how to write it correctly, any help would be greately appreciated
0
Comment
Question by:sab568
  • 5
  • 4
9 Comments
 
LVL 92

Expert Comment

by:objects
ID: 12304301
it'd be easier to store the names in an array.
0
 
LVL 92

Expert Comment

by:objects
ID: 12304306
> m = month + 12 * a;

try:

m = (month-1) * 9;
0
 

Author Comment

by:sab568
ID: 12304365
yes! that worked, now... the other problem i have with this script is that the spacing is weird. this is what the output is....

Thursday , January   1 2004

notice the weird spacing, what do you guys recomend changing while still keeping the same idea for the scirpt.
0
 
LVL 92

Expert Comment

by:objects
ID: 12304382
use String's trim() method to remove trailing spaces
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:sab568
ID: 12304392
where should i put the trim at? after the system.out.println or where?
0
 
LVL 92

Expert Comment

by:objects
ID: 12304400
NameOfTheDayOfTheWeek = s.substring(9 * d, 9 * d + 9).trim();
 NameOfTheMonth = g.substring(9 * m, 9 * m + 9).trim();
0
 

Author Comment

by:sab568
ID: 12304436
Perfect man, so how do I award you the points? do i just hit accept?
0
 
LVL 92

Accepted Solution

by:
objects earned 50 total points
ID: 12304442
> do i just hit accept?

yep :)
0
 

Author Comment

by:sab568
ID: 12304448
awesome!, thanks for the help. I have a couple more of these to do an be sure im going to have trouble with em :) please keep an eye out for my questions as you have been GREAT help

thank you,

sab568
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Fibonacci challenge 11 82
array6 challenfge 6 62
mapAB Challlenge 35 85
Eclipse Neon and jdk 1.8.0 11 66
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now