Find Day Number Of The Year?

Apr 15, 2014

figuring out the logic to print the day number of the year. The directions for my homework are: Write a program that prints the day number of the year, given the date is in the form: month day year. For example, if the input is 1 1 05, the day number is 1; if the input is 12 25 05, the day number is 359. The program should check for a leap year . I have a basic outline of the program but i am having trouble with figuring out the logic to display the day number of the year given the date. This is what i have so far

import javax.swing.JOptionPane;
 public class Practice4 {
public static void main(String[] args){
String monthStr;
String dayStr;
int inputMonth;

[code]....

View Replies


ADVERTISEMENT

Find The First Day Of Any Year?

Jan 25, 2014

write a program in java to enter a year and find out the first day of that year

View Replies View Related

Program To Determine Number Of Days In A Year Up To And Including The Current Day

Nov 23, 2014

So basically we have this question to do : Write a method dayNumber that determines the number of days in a year up to and including the current day. The method should have three int parameters: year, month, and day. If the value of any parameter is invalid, the method should print a warning message and return the value zero. The table gives some examples of the action of the method. Accept any non-negative year as being valid. You may want to assume the existence of a method numberOfDays that returns the number of days in a given month of a given year. And you should have a method call isLeapYear, if the user enter a year that is a leap year.

This is what I did so far:

class dayMonthYear {
public static void main(String[] args) {
System.out.println("Enter a year");
int year = In.getInt();
System.out.println("Enter the month for '1' to be January - '12' to be december");

[Code] ....

It works and compiles but my problem is that: let say I enter "12" for December and December has 31 days, so what my program will do since December has 31 days, it thinks each month has 31 days and add them up which will give me 372 when it's suppose to give me 365. How do I make it that it won't do that and that it will work if the year is a leap year too.

View Replies View Related

Find The Lowest Number?

Apr 12, 2014

I have to find the average, highest, and lowest numbers in an array. I already have the average and highest, and I thought I could find the lowest number the same way I found the highest, but it's not working. It just keeps coming out to 0. I've tried out different ways, but I want to see if there are better ways than doing MAX_VALUE for the lowest, then looping it through.

import java.util.Scanner; 
public class Test_Scores {
public static void main(String[] args) {
//array,scanner,values

[Code].....

View Replies View Related

Find Number And Sum Of All Integers

Oct 29, 2014

Write a program to find the number of and sum of all integers greater than 100 and less than 200 that are divisible by 7.

View Replies View Related

How To Find Whether A Number Is Palindrome Or Not

Aug 6, 2014

Any simplest code to check whether a number is palindrome or not?

View Replies View Related

Find Slot Number In Array?

Jan 30, 2015

what I needed to know to complete the lesson, but now it just tells me what the output should be and I have to research the information on my own. anyways, here is my code from the previous lesson:

import java.util.Random;
import java.util.Scanner;
public class tnArray {
public static void main(String[] args) {
int [] array;

[code]....

Now I have to change it so that instead of counting the number of times a number will appear in the array, I must output which slot in the array the number is in.

View Replies View Related

Find Number Of Rows In CSV File

Feb 13, 2014

I am working through a text and I am supposed to complete the following tasks.

Your ReadFiles.java class requires the following methods:

Method: check to see if the file exists

Method: find number of rows in csv file

Method: Converts the csv file to a mutli-dimensional array

Method: PrintArray

Method: Return array using a get method

Create a file DataAnalyzer.java. This file will be used to call the methods in ReadFiles.java. Be sure to demonstrate that all of your methods work through DataAnalyzer.java.

The problem is that it does not really provide any information on how to go about reading a file into an array. I am stuck at the third task of converting the file to an array and I have tried several ways to do this unsuccessfully. I thought that I would at least try to get things to print out (line 87) to see if I could get that to work, but all that prints in null over and over again.

Java Code:

public class DataAnalyzer {
public static void main (String[] args) {
ReadFiles aReadFiles = new ReadFiles();
aReadFiles.fileCheck();
aReadFiles.findRows();
aReadFiles.convertFile();

[Code] .....

View Replies View Related

Find Biggest Number From Array

Jun 26, 2014

I have 2 arrays in random order of 10 numbers.I need to find the biggest number from array A and B and then when its on a screen second thing is to multiply those numbers by 2.

import java.util.Random;
public class Projektas {
public static void main(String arng[]){
int i,j;
int A[] = new int [10];
int B[] = new int [10];;

[code]..

View Replies View Related

Java Math - Find Imaginary Number

Nov 2, 2014

I am doing this math for my assignment where you have to find the imaginary number.

double dem = (b*b-4*a*c)*-1;
double dem2 = Math.sqrt(dem);
realPart = (-b/(2*a));
imagine = (dem2)/(2*a);
imagineneg = (dem2)/(2*a);

So basically I am trying to get it that the number inside the square root isnt negative. So lets say I enter a: 1, b: -1, c: 4.25. When you do the discriminant it would be -16 but I want that to be positive so I multiple it by -1 (thats the dem part). Then I sqaure root the whatever the answer is and then go to the imagine and imagineneg part where you find the imaginary number.

My problem is that instead of it being -16*-1 to get 16, some how I get 15.

View Replies View Related

Find If Number Entered By User Consecutive Or Not

Feb 21, 2014

I need to find if the number entered by the user are consecutive or not!

Ex:this should return a true!! This should return false!

(1,2,3) (3,5,7)
(3,2,4) (1,2,2)
(-10,-8,-9) (7,7,9)

My program seems to work ok when i enter number in order like 1,2,3 = true , and all the numbers for false seem to be working as well! my problem is when i enter number like 3,2,4 that are not in order but still are consecutive!! I thought that another if statement would be the solution but i have tray several different ones and still can't make it work !!!

Java Code:

import java.util.*;
public class Consecutive{
public static void main (String [] args){
Scanner console= new Scanner(System.in);
System.out.println("Enter three numbers");
String numbers = console.nextLine();

[[Code] .....

View Replies View Related

How To Find How Many Times A Number Appears In Array

Dec 7, 2014

This is my code up to now and I can't do anything to make it work. I want it to tell me how many times the number 3 appears, and the last position it was in. I am getting errors like"Cuanto.java:88: getPosition(double[],double) in Cuanto cannot be applied to (double) ....

a = getPosition(a);" and unreachable statements, and value not found. It's all over the place every time I make a change to it.

Java Code:

public class Cuanto {
static int getPosition(int count,double listOfValues[],
double targetValue) {
int a = 0, i;
for (i=0; i < listOfValues.length; i++) {
if (listOfValues[i] == targetValue) {
a++;

[Code] ....

View Replies View Related

Find ASCII Number Of Names Entered

Sep 12, 2014

I am having a problem with SD array .i have to find the ASCII no. of names entered.

import java .io.*;
class ASCII
{
public static void main()throws IOException
{
InputStreamReader read = new InputStreamReader(System.in);

[Code] .....

View Replies View Related

Java - Find Number In Given Array Of Integers

May 2, 2014

I wrote this simple piece of code to find the number in the given array of Integers. The program works fine although it shows a couple of errors when i modify it a little bit.

public class DemoLabel{
public static void main(String [] args){
int[][] arrofInts={
{32,45,67,87},
{23,44,55,66},
{12,47,87,56},
{23,44,12,78}

[Code] .....

In the disp() method,Suppose i only want to pass two arguments i.e disp(i,j) given that searchFor variable is visible in the entire class but when i use disp(i,j) i get the following error

DemoLabel.java:38: error: cannot find symbol System.out.println("The number "+searchFor+" is at the location"+i+" , "+j);
^
symbol: variable searchFor
location: class DemoLabel

So i decided to declare the

int searchFor
as
public int searchFor

But the compiler threw another error saying that it was a Illegal start of expression

Also,when i add a SOP line after the label search: it shows the error

DemoLabel.java:25: error: undefined label: search
continue search;
^

Although i got the program to work it would be useful if i could understand why it doesn't work with the modifications.

View Replies View Related

Find Number Of And Sum Of All Integers Greater Than 100 And Less Than 200 Divisible By 7

Oct 30, 2014

 Write a program to find the number of and sum of all integers greater than 100 and less than 200 that are divisible by 7.

View Replies View Related

Find Biggest Corner Based On Number Zero

Apr 23, 2014

The program should find the biggest corner, based on the number zero.

A zero becomes a corner when there's the same amount of zeros under it, and left to it.

The program should print a message saying what's the biggest corner size.

Corner size is the number of zeros inside it.

Java Code:

import java.util.*;
class Corners
{
static Scanner reader=new Scanner(System.in);
static final int N=25;
static int corners(int a, int b, int[][] m)

[Code] ....

That's the output:

Java Code:

The BOX:
1 0 0 1 1 1 0 1 0 1 0 0 1 0 0 0 1 0 0 0 0 0 1 1 1
1 0 1 0 1 0 0 1 0 0 0 1 0 1 1 1 0 1 0 0 0 1 1 1 0
0 1 1 1 1 1 0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 1 0 0 0
0 1 0 1 0 1 1 1 1 1 1 0 0 0 1 1 0 0 1 1 0 1 0 0 1
0 0 1 1 0 0 0 0 0 1 0 0 0 0 1 0 0 1 0 0 0 0 1 1 0

[Code] ....

View Replies View Related

Find The Column With Highest Average Number

Feb 14, 2015

code a 10 * 10 matrix, with random numbers from 1 to 100,

i) Find the most repeated number.
ii) Use the Binary Sort, to sort the matrix in ascending order.
iii) Find the Column, with the highest average number.

View Replies View Related

How To Find How Many Number Of Elements Are Landing In Same Bucket In HashSet

Jan 12, 2015

Is there any way to find how many number of elements are landing in same bucket in HashSet. I know Reflection could be one way but i am not able to design a program for that.

View Replies View Related

How To Find Smallest Number In A Group Of 3 Numbers Using While Loop

Mar 23, 2015

import java.util.Scanner;
public class AvgLrgSml{
public static void main(String[]args){
System.out.print("Hello there. Please enter any three numbers.");
Scanner keyboard = new Scanner(System.in);
double num1 = keyboard.nextDouble();
double num2 = keyboard.nextDouble();

[Code]...

View Replies View Related

Java Program - Find Next Highest Or Lowest Prime Number

May 2, 2014

Java program takes positive int from user and determine if prime. Next the program finds next highest or next lowest prime number.

import java.io.*;
import java.util.*;
public class pa2take2 {
public static void main (String[]args){
int menus; //menu selection

[Code] ......

View Replies View Related

Unable To Find Prime Palindrome Numbers Less That A Number By Program

Oct 10, 2014

I want to find the prime palindrome numbers less that a given number by my program. Here is my code, I am trying to find the method to solve the errors when I compile it. It said variable a might not have been initialized in line 41,62,86.

import java.util.Scanner;
public class Lab5{
public static void main (String[] args){
System.out.println("Please input a number");
Scanner Input=new Scanner(System.in);
int num = Input.nextInt();

[Code]...

View Replies View Related

PPS Number Generation - Netbeans Displays (Cannot Find Symbol) And Program Fails To Run

Jan 22, 2015

I am writing a payroll program .The program generates random PPS numbers and then takes in users information and calculates the salary accordingly. I am using netbeans and my code is showing errors on line 18 and 42 ("cannot find symbol")on the code for grossPay(). The program seems to crash after a new PPS number is generated and will not run.

package sd_assg_2;
import java.util.Arrays;
import java.util.Random;
import javax.swing.JOptionPane;
public class SD_ASSG_2 {
  public static void main(String[] args) {
String[] newPPs = getPPSno();

[Code] ....

View Replies View Related

Get Month And Year From Calendar

Aug 8, 2014

I have Georgian Calendar object

GregorianCalendar date = (GregorianCalendar)pageContext.getAttribute("datetime");
System.out.println("date :::: "+date);

It prints :

date :::: java.util.GregorianCalendar[time=1408045500000,areFieldsSet=true,
areAllFieldsSet=true,lenient=false,zone=sun.util.calendar.ZoneInfo[id="GMT+05:30",
offset=19800000,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],
firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2014,MONTH=7,

[Code] ....

I want month and year from this like August 2014. How can i do the same.

View Replies View Related

How Does Program Know To Calculate For Only One Year

Mar 26, 2015

how does the program know to calculate for only one year?

public class Interest2 {
public static void main(String[] args) {
double principal; // The value of the investment.
double rate; // The annual interest rate.
double interest; // The interest earned during the year.

[code]....

View Replies View Related

Day Of Year With Users Input

Apr 8, 2014

I'm doing a problem where I convert users input for the date (MM/DD/YY) into a written out date and year. That part is fine. The part I'm struggling with is then indicating what day that is in that year. how to use the user inputted MONTH, DAY, and YEAR to then get the day of year.

import java.util.Calendar;
import java.util.Scanner;
import java.util.regex.MatchResult;
import javax.swing.JOptionPane;
public class ConvertDate {

[code]...

View Replies View Related

Calculating Rainfall Quarterly Per Year

Mar 30, 2015

//calculates rainfall quarterly per year
 
import java.util.Scanner;
 public class SophiaKeyProgram2 {
 public static void main(String[] args) {
// TODO Auto-generated method stub
 
int numQuarter; //number of quarters in a year
double rainfall=0; //the amount of rain

[Code] ....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved