Java Program That Prints Specific Numbers In Pattern
Dec 30, 2014
Write a java program that prints 0..........121..........23432..........3456543............456787654............56789098765 in this pattern?
My code:
public class Number {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int k=0;
for(int n=0; n<=10; n=n+2)
[code]....
View Replies
ADVERTISEMENT
Nov 23, 2014
I have to make a program that prompts the user to enter 10 numbers and at the end it prints out the distinct numbers and then the other numbers that weren't repeated...
I have the part where it prints out the distinct numbers but I stuck on how to make it print out the other numbers that didn't repeat...
import javax.swing.JOptionPane;
public class DistinctNumbers {
public static void main(String[] args) {
String getInput;
int input;
int[] numbers = new int[10];
[Code] ....
View Replies
View Related
May 9, 2015
Here is my code :
import java.util.Scanner;
public class smallestnumber
{
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
int smallest =0;
int number;
[Code]...
here is the output of my code:
Enter the number
88
Enter the number
8
Enter the number
6
Enter the number
55
[Code]...
Why is it printing 0 instead of 1?
View Replies
View Related
May 10, 2015
I am trying to write a java program that prints out the number that is the mathematical constant e. As you input a number, the larger it gets , the closer it comes to 2.71828 . Here is my code:
//taylor series that prints out e^1=1+1/1!+1/2!+1/3!+.....
import java.util.Scanner;
public class taylor_1
{
public static void main(String args[]) {
Scanner input=new Scanner(System.in);
int factorial =1;
[Code] .....
Here is the output of my code:
enter n
9
Taylor series is 9.0
View Replies
View Related
Oct 5, 2014
My son want to create a java program (Diamond shape) that can plot graph for with the following data.
Pattern type is:
* *
* *
*
* *
* *
*
View Replies
View Related
Jun 27, 2014
I am trying to make a java program which should count the occurrences of a specific character in a string. I have 1 error - "cannot find method charAt(int)". Here is what I have.
import java.util.Scanner;
public class ch4q5 {
public static void main(String[] args) {
String input ;
String t ;
int c = 0;
[Code] ....
View Replies
View Related
Jan 31, 2015
I'm trying to create a circular array which prints out 8 numbers that increase by one and don't exceed 9. If they do, the remaining numbers are printed from 0 on-wards. I have code below which does this job, but it doesn't really use an array to loop back.
Java Code:
package Practice;
public class Practice
{
public static void main(String[] test)
{
number(7);
number(9);
[code]...
View Replies
View Related
Aug 7, 2014
i am fairly new to java but have made a few projects so i do know most aspects that would allow me to complete the task its just i have been stuck at the same place now for 2 days.The project is to create a java program that can read specific data within a csv file to work out the averages etc. The csv file is a database of different weather stats . an example of the first 12 months of the csv file is below..
[CSV FILE]
year ,month,average rainfall etc
1946 15.70.616108.131.5
1946 28.23.56111.871
1946 38.82932.9 102.9
1946 414.16.3029.2 150.5
1946 513.96060.7 143.6
[code]...
I know that once the data is indexed i can than use a double to find the average of the 12 specific pieces of data and so on. once this is complete i should than be able to transfer the data to a simple graph.
View Replies
View Related
Feb 4, 2015
When I run this code, it is supposed to get one value from turnTimer(); and return it, just as a test. This works when I enter a valid pit. For example. If I were to input "A" when it's player one's turn, it will return 1, like it should. However, if I were to type "H" when it's player one's turn, it returns "Not a valid pit!"(like it should) but then it also returns 12. It shouldn't know that H is 12 because it's in a separate method. I'm confused as to why it's printing both values.
import java.util.*;
public class Mancala {
static Scanner input = new Scanner(System.in);
public static int pit;
public static void main(String[]args) {
Mancala mancala = new Mancala();
int[] board = {0,3,3,3,3,3,3,0,3,3,3,3,3,3};
[Code] .....
View Replies
View Related
Feb 4, 2015
When I run this code, it is supposed to get one value from turnTimer(); and return it, just as a test. This works when I enter a valid pit. For example. If I were to input "A" when it's player one's turn, it will return 1, like it should. However, if I were to type "H" when it's player one's turn, it returns "Not a valid pit!"(like it should) but then it also returns 12. It shouldn't know that H is 12 because it's in a separate method. I'm confused as to why it's printing both values.
import java.util.*;
public class Mancala
{
static Scanner input = new Scanner(System.in);
public static int pit;
public static void main(String[]args)
{
Mancala mancala = new Mancala();
int[] board = {0,3,3,3,3,3,3,0,3,3,3,3,3,3};
[code]....
View Replies
View Related
Feb 8, 2014
I was told to create a program that prints the time between 00:00 (0:00 a.m.) and 23:45 (11:45 p.m.) in the 24-hour clock and 12-hour clock format like this:
24-hour Clock 12-hour Clock
-----------------------------
00:00 0:00 a.m.
00:15 0:15 a.m.
00:30 0:30 a.m.
00:45 0:45 a.m.
01:00 1:00 a.m.
01:15 1:15 a.m.
01:30 1:30 a.m.
01:45 1:45 a.m.
02:00 2:00 a.m.
ect...
but cant seem to create the program and my program doesnt seem to run.
View Replies
View Related
Apr 8, 2015
So I'm trying to write a program that prints out the "most-repeated integer" in an Array.
For example: if an array contains {1,2,2,3} It would print out 2 as the result.This is what I got so far and according to my knowledge I think I'm correct but for some reason it doesn't work.. Please give me some inputs.
public class MostInt{
public MostInt (){
int[] array = {0};
for(int i = 0;i>array.length;i++){
if(i==i++){
System.out.println(i);
[Code]...
View Replies
View Related
Feb 15, 2015
I was inquiring about selecting random numbers from a Fibonacci array, the original post for which is here: Exiting a 'for' Loop Early. I have managed to achieve this with the following code:
System.out.println("Random numbers from the Fibonacci array");
for(int i = 0; i < limit; i++) //Limit is an 'int' of 15 & is set as the length of the Fib. array. I'm calling it for the Random array, too!!
{
Random dice = new Random();
int randomIndex = dice.nextInt(array.length); //The Fib. array was simply called 'array'!!
if (array[randomIndex] < 100)
{
System.out.print(array[randomIndex]+ " ");
}
}
When the code prints I get a random set of numbers which occur in the Fibonacci sequence preceding it. However, the actual length of this Random array also changes each time, and never more than the limit of 15 specified in the 'for' loop. What I want to try and do is print the Random array with a specific length each time. I've tried changing the conditional statement of the 'for' loop in different ways to set the Random array's length, but had no luck.
View Replies
View Related
Jan 30, 2014
I want to develop an simple application using java for a simple porgram for the addition of two numbers.
View Replies
View Related
Jan 21, 2015
This program simply adds integers to an ArrayList and then prompt the user if they would like to delete specific numbers that they don't want.
The output that I get when I want to delete numbers like 2 and 4 from 1 2 3 4 5 is 1 2 3 4 5 instead of 1 3 5.
Java Code:
import java.util.ArrayList;
import java.util.Scanner;
public class AL
{
// A regular array like int arr[] has to have its size declare before run-time and it's not dynamic which mean it can not grow or expand on its own.
static Scanner input = new Scanner(System.in);
// You have to use reference types(Integer, Double, Float); not primitive types(int).
[Code] .....
View Replies
View Related
Jan 9, 2015
Write a program (TwoIntegers.java) that prompts the user to enter two positive integers and prints their sum (by addition), product (by multiplication), difference (by subtraction), quotient (by division), and remainder (by modulation). When the user enters 5 and 3, the output from your program should look exactly like the following:
Enter two positive integers: 5 3
The sum is 8.
The product is 15.
The difference is 2.
The quotient is 1.
The remainder is 2.
import java.util.Scanner;
public class TwoIntegers {
public static void main(String[] args) {
System.out.println("Enter two positive integers: ");
Scanner userInput = new Scanner("System.in");
int integer1 = userInput.nextInt();
int integer2 = userInput.nextInt();
[code]....
View Replies
View Related
Nov 18, 2014
Write a program that asks the user for an integer andthen prints out all its factors in increasing order. Use a class FactorGenerator with a constructor FactorGenerator(int numberToFactor) and methods nextFactor and hasMoreFactors. Supply a class FactorTester whose main methods reads a user input, constructs a FactorGenerator object and prints the factors.
Here is what I have so far for my main class and tester class
public class FactorGenerator
{
int factor;
int number;
int x;
FactorGenerator(int numberToFactor)
{
number = numberToFactor;
}
[Code]....
View Replies
View Related
Aug 20, 2014
java program to convert integer to Roman numbers and vice versa?
View Replies
View Related
Dec 6, 2014
Let's say if I want to create a dot file that print this graph in Java, how do i go about it?
I'm starting with this:
PrintWriter writer = new PrintWriter("graph.dot");
View Replies
View Related
Feb 24, 2014
The class Overloading below asks for two names and prints three different greetings. Your task is to write the class methods missing from the class declaration. Methods print the greetings as shown in the example print.
Hint:The names and parameter types of the needed methods can be checked from the main method because all methods are called there. This exercise also does not require you to copy the source code below to the return field.
The method declarations will suffice.
Example output
Type in the first name: John
Type in the second name: Doe
**********
Hi!
**********
Hi, John
**********
Hi, John and Doe
**********
import java.util.Scanner;
public class Overloading {
public static void main(String[] args) {
String firstName, secondName;
[Code] ....
View Replies
View Related
Jul 3, 2014
I have code which validate code enter by user
the requirement say the maxlength=2 and minlength=1 and is a string
the user can enter code as follows
00
A1
HH
12
10
09
I have this Java Code:
public boolean isValidPattern(String s_value, String s_pattern) {
boolean flag = false;
if (Pattern.matches(s_pattern, s_value)) {
flag = true;
}
return flag;
[Code] ....
My problem is when user put
A1 AM geting error
View Replies
View Related
Jun 27, 2014
I'm having a hard time implementing a simple composition example in Java:
Java Code:
public class CompositionPattern {
public static void main(String[] args) {
Udp udp = new Udp();
Imap imap = new Imap();
udp.startService();
imap.startService();
[Code] ....
The above won't compile. It says "The method supportsMe() is undefined for the type Object". I understand that I stored parent as an Object. But in reality it is not simply Object, but a Udp object or Imap object. The point is to make Responder generic. I don't want to have to cast the Object to Udp or Imap. Any solutions so I can keep this generic?
View Replies
View Related
Apr 21, 2003
I have heard about using patterns in core java.Is it possible?If yes, how?
View Replies
View Related
Jul 16, 2014
The program I'm working on is supposed to read input from a file and using recursion, print the pattern of asterisks for each value until the value is either < 0 or > 25. For example, if the value was 4, the pattern would look like this
*
* *
* * *
* * * *
* * *
* *
*
The values are stored in a file entitled prog3.dat which looks like this
4
3
15
26
0
I've never used recursion before and haven't been able to find anything showing how it would work with this particular type of problem. Here is what I've been able to come up with so far, but I'm having problems still which I will show following the code.
import java.util.Scanner;
import java.io.*;
public class Program3 {
public static void main(String[] args) throws Exception {
int num = 0;
java.io.File file = new java.io.File("../instr/prog3.dat");
Scanner fin = new Scanner(file);
[Code] ....
Output:
Please enter an integer
*
* *
* * *
* * * *
Please enter an integer
*
* *
* * *
Please enter an integer
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * * * *
* * * * * * * * * * *
* * * * * * * * * * * *
* * * * * * * * * * * * *
* * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
Please enter an integer
Please enter an integer
As you can see, I don't know how to make it print the pattern like in the example and am honestly not even sure if this is recursion since I've never actually worked with recursion before.
View Replies
View Related
Jul 3, 2014
I have code which validate code enter by user. The requirement say the maxlength=2 and minlength=1 and is a string, the user can enter code as follows :
00
A1
HH
12
10
09
I have this code
public boolean isValidPattern(String s_value, String s_pattern) {
boolean flag = false;
if (Pattern.matches(s_pattern, s_value)) {
flag = true;
[Code] .....
my problem is when i put
A1 is still giving error
View Replies
View Related
Mar 9, 2014
I am to design a program in java that will allow a user to Input a list of your family members along with their age and state where they reside. Determine and print the average age of your family and print the names of anyone who live in Texas. I have tried but my results are wrong.
View Replies
View Related