Unable To Print Values As Specified

Feb 8, 2015

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.Find the sum of all the multiples of 3 or 5 below 1000.

public class ClassEcerciseOne {
public static void main(String[] args) {
// TODO Auto-generated method stub
int x=0;
int y=0;
for (x=0;x < MAX_VALUE;x++){
if (x/3==0){
System.out.println(x);
int z= x++;

[code]...

View Replies


ADVERTISEMENT

Unable To Print Sum Of First Row?

Dec 11, 2014

Java Code:

public class Lab12 {
public static int SumRow(int [][] a){
int row, column, sum=0;
for (row=0;row<2;row++ ) {
sum=0;
for (column=0;column<2;column++) {
sum=sum+a[row][column];

[Code]...

my output is

The sum of row 1 is: 3
The sum of coloumn 0 is: 5
The sum of coloumn 1 is: 5
The max of row 0 is: 4
The max of row 1 is: 2

it is supposed to print the sum of row o first ?

View Replies View Related

Unable To Print Out Randomly Generated Array

Nov 19, 2014

i am trying to print out a randomly generated array, but i only get

[I@7852e922

i did some research and the "[" is for arrays, "I" is for the int and "@" is the hash. and the rest is some sort of hex. I need to override this in a way, but i can't seem to find out how.
this is my current code:

import java.util.Random;

public class Oppgave {
public static void main(String[] args){
int myint[] = fyll();
System.out.println(myint);
}
public static int[] fyll() {

[Code]...

View Replies View Related

Unable To Print Repeating Integers In Array

Aug 5, 2012

I have a problem where i have to write some code to read through an int array and print out the different integers and how many times they occur. For example:

if the array contained the numbers 1,4,2,3,5,4,4,7,5,4,3,6,8,6,4,

i would need the print to appear something like this

integer: 1, times: 1
integer: 4, times: 5
integer: 2, times: 1

etc

as the array is read sequentialy from element 0 to the end. the program should find the integer value in the first element (increment a counter by 1) and then search all other elements to see if the integer reoccurs (counter++ for each time it reappears). obviously the counter would be the 'times' value in the second column.

My problem is i can get this accomplished yet i cant get the program to recognise when it has already registered an integer in a previous element and skip to the next element looking for a new integer. SO for each element in the array it prints the integer and then searches the entire array for the integer again and increments the counter accordingly. so in essence there is a line printed for each integer the number of times it actually occurs.

I simply wish to have my code to find an integer and the number of times it occurs. and then disregard the elements it has registered the previous integer in.

Also, keep in mind that i am NOT permitted to use any new data structures/arrays for storing/remembering values. I can only use int and double variables throughout.

what i have so far is this: with the array being customerID[] :

Java Code:

int num;
int counter;
for(int count = 0; count < customerID.length; count++)
{
counter = 0;
num = customerID[count];
for(int count2 = 0; count2 < customerID.length; count2++)

[Code]...

The output for the int array 1,1,3,0,3,2,0,4,1,3, looks something like this:

Integer: 1, Times: 3
Integer: 1, Times: 3
Integer: 3, Times: 3
Integer: 0, Times: 2
Integer: 3, Times: 3
Integer: 2, Times: 1

[Code]...

and as you can see lines are repeated for each time the same integer occurs in a new element. i just need my code to skip an element if the integer has been previously encounterd and recorded. i.e i need it to look more like this :

Integer: 1, Times: 3
Integer: 3, Times: 3
Integer: 0, Times: 2
Integer: 2, Times: 1
Integer: 4, Times: 1

with the first encountered integer being checked throughout the array and then moving to the next integer/element which is not the same as any previous.

View Replies View Related

I/O / Streams :: Unable To Create A Print Writer To Write To File

Apr 25, 2014

I am completing a USACO online problem and am trying to create a print writer to write to my file(ride.out). I did this:

PrintWriter out = new PrintWriter(new BufferedReader(new FileWriter("ride.out")));

However, a load of undefined constructor errors come up for PrintWriter(BufferedWriter) and BufferedWriter(FileWriter). I have imported java.io.* so I don't know what the issue is. This has worked before.

edit: bufferedreader? i give up(not literally)

View Replies View Related

Unable To Print Out Results Of Program That Calculate Number Of Seats

Nov 11, 2014

I'm trying to print out the results of a program that calculates the number of seats the parties will get in an election.I have to print the partial results and the national results.

I can print te number of seats per party in each constituency, but how can i sum all seats per party in each constituency and print the national results?I'm working with vectors, which I know it might not be the best option, but everything is working, except the fact that I can't loop throuhg the vector and retrieve the total sum per party.Like, adding the seats for labour party in Constituency A and B and C, etc, and print the sum. And do the same for conservative party.Is it possible, or doIhave to create a method in Parties class to solve the problem?

This is what I have now.

for (Parties p : h.geral) {
show += String.format("Constituency - %5s - %5s - %d%n",
p.getConstituency(), p.getParty(), p.getNum_seats());
}

View Replies View Related

JSP :: Unable To Pass Values From Page To Servlets

Aug 12, 2014

I am trying to pass values from JSP Page to Servlets but I am getting a NullPointerException

Here is my JSP code

<html>
<head>
<title>Student Registration Form</title>
<style type="text/css">
h3{font-family: Calibri; font-size: 22pt; font-style: normal; font-weight: bold; color:SlateBlue;
text-align: center; text-decoration: underline }
table{font-family: Calibri; color:white; font-size: 11pt; font-style: normal;

[Code]...

View Replies View Related

Unable To Get Values From JTable And Insert Them In MySQL Database

Feb 7, 2014

i have a problem, im trying to get some values from a jtable (tabla) and insert them in a mysql database, so i scan the table for some values to know which of the rows i must insert ("s" or "n").

I'm able to insert few rows, but when the last row with "s" or "n" is inserted it launch me a NullPointerException and I dont know why.

public void insertar(JTable tabla, int rowt, int colt) throws ParseException{
String documento=null, cve_clie=null, fechaE=null, fechaR=null, check=null;
char d=' ',dd=' ',m=' ',mm=' ',y1=' ',y2=' ',y3=' ',y4=' ';
String chck = null;
try{
conexion = connMysql.mysql();
String squery="insert into consefact3 values (?,?,?,?,?)";
PreparedStatement pst = conexion.prepareStatement(squery);

[Code]...

View Replies View Related

Unable To Match Input String With Range Of Values And Getting PatternSyntaxException

Jun 12, 2014

I am trying to match the input string with range of values and getting PatternSyntaxException. below is my code

public static void main(String[] args) {
String regex="01[4-6]";
String code="015";
boolean bool=code.matches(regex);
System.out.println(bool);
}

output: true

But when i try to give range in double digits, it throws exception. What if i have to match a number(as string) between 10 to 25 or like that.

public static void main(String[] args) {
String regex="0[14-16]";
String code="015";
boolean bool=code.matches(regex);
System.out.println(bool);
}

Output:

Exception in thread "main" java.util.regex.PatternSyntaxException: Illegal character range near index 5
0[14-16]
^

View Replies View Related

How To Print First 5 Values

Nov 16, 2014

See the below:

public static void main() {
int i; // counter
  createDeck(); // this is a function call
  // Show the cards in the deck
System.out.println("The deck is as follows:");
for (i=0 ; i < CARDS_IN_DECK ; i++)

[code]....

It is now printing out the value of myDeck[5] but I need to print out first 5 values.

View Replies View Related

JSP :: How To Print Null Values In EL

Dec 18, 2014

The value is: ${object1.property1} If the value of the property is null, I want "null" to be printed, like this:

The value is: null But I get an empty string, like: The value is:

I know I can use a ternary operator, but isn't there a simpler/shorter solution? A function (like NVL() in SQL)?

The value is: ${empty object1.property1 ? "null" : object1.property1 }

Not only is this long, but the value expression is typed twice, which is a magnet for bugs.

View Replies View Related

Adding To Print Out Values

Sep 6, 2014

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Hmwk1 {
public static void main(String[] args) {
String fileName = "lotto.txt";
final int arraySize = 45;
int[] count = new int[arraySize];

[Code] .....

My problem is where do I start or add the following code to be added?

I only want to use 1 array and may be or should I try a catch block? The number or numbers that were picked least frequently.

The average number of times that all of the numbers were picked. For example, the average might have been 210 times.

The number or numbers that were picked the average number of times.

The number or numbers that were picked most frequently.

View Replies View Related

Print All Values In A Format Showing Their Key

Jun 14, 2014

Java Code:

public static void main(String[] args) {
HashMap<Integer, String> stuff = new HashMap<>();
stuff.put(1, "Book");
stuff.put(2, "Pancake");
stuff.put(3, "Waffle");

for(Map.Entry thing : stuff.entrySet())
System.out.println(thing.getKey() + ": " + thing.getValue());
} mh_sh_highlight_all('java');

So I make a HashMap which is pretty simple. My book showed me how I would print all the values in a format showing their key a ": " and the the actual value. What I don't understand is why the type element for the for each loop is the interface, Map.Entry.

View Replies View Related

Program Prints 2 Values When It Should Only Print 1

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

How To Print TreeMap Values In Reverse Order

Apr 3, 2014

Below codes find the character frquency how to print this in reverse order using comparator or else

public static void main(String arr[]) {
String s="bebeao";
Map<Character,Integer> chars=new TreeMap<Character,Integer>();
for(int i=0;i<s.length();i++) {
char x=s.charAt(i);
Integer count=chars.get(x);
if(count==null)

[Code] .....

View Replies View Related

Sort Values In Array And Print Median Value On Console

Oct 22, 2014

Use the sort method of the arrays class to sort the values in the array, and print the median value(the 50th value) on the console followed by a blank line. Then, test this enhancement. Print the 9th value of the array on the console and every 9th value after that. Then, test this enhancement.

import java.util.Arrays;
public class ArrayTestApp
{
public static void main(String[] args) {
double [] arrayTest = new double[99];
//adding random number to each element in the array
for(int i=0; i<arrayTest.length; i++)
arrayTest[i] = 100.0*Math.random();

[Code] ....

OUTPUT

run:

The average is: 49.842845462514944
The median is: 49.68753724038633
The 9th value is: 2.599530043466969
The 9th value is: 11.486193141397095
The 9th value is: 20.14206270200648

[Code] ....

View Replies View Related

Print Maximum And Minimum Values Of Integers From User Input

Apr 27, 2015

So I'm learning java from a website and I was tasked with creating a simple program which allows the user to enter a series of integers, then finally when they decide to input a non-integer the program will print the maximum and minimum values of the integers they entered. So for example if they entered 5, 4, 3 and 2 then enter a non-integer the program would output 5 (maximum value), then 2 on a new line (minimum value).

Here is my code:

import java.util.Scanner;
public class MaxMinPrinter {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int max = Integer.MIN_VALUE;
int min = Integer.MAX_VALUE;

[Code] ....

And this is what the output looks like:

Actual output
-------------------------------------------
Enter an integer: 5
- 10
-
- Enter an integer: -4
- 8
- -6
-
- Enter an integer: 11
- -1
-
- Enter an integer: q
- -1
- -6

When it's supposed to look like this:

Expected output
-------------------------------------------
Enter an integer: 5
Enter an integer: 10
Enter an integer: -4
Enter an integer: 8
Enter an integer: -6
Enter an integer: 11
Enter an integer: -1
Enter an integer: q
11
-6

View Replies View Related

For Loop To Count Values Of Stack Of Quarters From 1.00 To 3.00 And Print Value Of Each Iteration

Nov 2, 2014

I had to write a foor loop to count the values of a stack of quarters from 1.00 to 3.00 and I had to print the values, that I understood and got it working so I taught the next assignment was going to be easier but I am having a hard time with it. For this one I have to write a for loop to print all the positive integer factors of 144 and I am supposed to print of factor per line but I tried doing that but it doesn't work it just prints out 144.

This is my code. The quarter assignment is also in there because it is part of a lab so just ignore that part since it is working correctly.

public class ForLoopPractice
{
public static void main(String [] args)
{
// Write a for loop to count out the values of a stack of quarters from $1.00 to $3.00
// Print the value of each iteration. Print this all on one line, rounded to the nearest cent.
// To print rounded, use printf, with a placeholder of %.2f
// (%f is the floating-point placeholder; the .2 indicates the number of decimal places)
/* YOUR CODE HERE */
for (double q = 1.00; q <= 3.00; q += .25)

[Code] ....

View Replies View Related

Unable To Print A Loop Inside Array Of Greater Size Than Loop Itself

Jan 27, 2015

I am trying to print a loop inside an array of a greater size than the loop itself. Like for example I have an array of size 7 but it has only 3 elements.

int[] array=new int[7]
array[0]=2;
array[1]=3;
array[2]=4;

now what I want to do is print these three numbers in a loop so that my array[3]=2;array[4]=3;array[5]=4 ...... till the last one. Also the array could be any size and not just 7.

View Replies View Related

Arrays And Number Generator - Determine And Print Largest And Smallest Values

Dec 4, 2014

/*
Purpose: To write the methods and the rest program. The program should fill a 4 X 4 2 dimensional array with random numbers between 100 and 200. The program should then determine and print the largest and smallest values within the array using two Methods Largest and Smallest. The program should then determine and print the number of values within the array that are even using a function called Even. The program should also enter a loop that will only terminate when the user inputs a -1 as a choice. The loop should continue to ask the user to guess a number that was randomly generated. The program should call the Findit function to determine if the number was in the array. The program should print out the values in the array when the user selects a -1 and then terminate.
*/

import java.util.Scanner;
import java.util.Random;
public class LNFI_2DArray
{
public static void main(String[] args) {
int guess;
int[] array = new int[4];

[Code] ....

I just had this code working, then all of a sudden i was hit with a 'keyboard leak' error code.

View Replies View Related

How To Make Print Employee Button To Print Info Of Other Class

Apr 12, 2014

Basically the class is supposed to have a static variable that keeps track of the number of companies (numberOfCompanies) that have been created and a static method that returns the value of this variable. I need to have a constructor and a method to addEmployee, a method to printCompany, and a toString method. The addEmployee method will check that there is only 1 salesperson, 2 designers, and 4 manufacturing persons at a time and will check that there are no more than 7 employees of the company.

The addEmployee method will return a String indicating what the error is (i.e. "There is already a sales person in this company") or a null if the employee was added. If attempting to name a third company, an error message will be shown. what i have so far but my print company mmethod returns null company class :in which i am obliged to use inputdialog because it says that it cannot return void when i use the showmeassage diaolog.

company class:

import java.util.ArrayList;
import javax.swing.JOptionPane;
public class Company {
private ArrayList<Employees> list ;
private static int numberOfCompanies;

[Code] ....

error message when print button is clicked:

Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: JOptionPane: parentComponent does not have a valid parent
at javax.swing.JOptionPane.createInternalFrame(Unknown Source)
at javax.swing.JOptionPane.showInternalOptionDialog(Unknown Source)
at javax.swing.JOptionPane.showInternalMessageDialog(Unknown Source)

[Code] ......

View Replies View Related

Two Threads - One Will Print Odd And Other Will Print Even Numbers In Sequence

Jul 25, 2014

I want to create two thread one thread will print odd number and another thread will print even number. but the number should be in a sequence like

1 2 3 4 5 6 7 8 9 10

View Replies View Related

Store Pixels Values Currently On Screen And Compare Them To Values On The First Frame?

Aug 29, 2014

I need a way to store the pixels values currently on the screen and compare them to the values on the first frame. Right now I'm using glreadpixels as follows:

currentBuffer= BufferTools.reserveByteData(mapSize);
glReadPixels(mapStartX, mapStartY, mapWidth, mapHeight, GL_BLUE, GL_UNSIGNED_BYTE, currentBuffer);
for (int i = 0; i < mapSize; i++) {
if (currentBuffer.get(i) != baseBuffer.get(i)) {
//Do nothing
continue;
}
//Do something
}

This works perfectly fine but turns out to be a real bottleneck, dropping the fps to a third of what it was. Is there any quicker way? All I'm after is speed, I don't even need to show it on the screen if the comparison is made "behind the scene".

View Replies View Related

Servlets :: How To Send Multiple Values Of Same ID But Different Values Of HTML

Feb 27, 2015

I have a question in mind that this is my registration form. I am sending these values from HTML form to server and database. I have question that in my case if I click next to Add Another Mobile no in HTML.then a block is genereated and each time a new name is generated.

My Question is if I click 6 times then 6 name attribute are generated. How can I send and differentiate them on my server side.

Because at their I will use something request.getAttribute("Attr_Name");

But they are same. How to do this?.

View Replies View Related

Instead Of Different Values In Two Columns Per Row In Jtable Getting Same Values

Feb 5, 2014

I have a JScrollPane with two coulmns. In the first column I have an image pane JTable, and in the second a list with names of sections. This second column I try to divide in two columns, one (the second column) to display the names of the sections (each row contains one name), and in the other column (the third) I want to show some values for every section in the row respectively. But, instead of displaying the desired values in the third column, I get the same names of the sections as in the second column.

View Replies View Related

Passing Values To Two Classes And Retrieving Values From Those Classes

Feb 14, 2015

I'm doing an aggregation exercise that's suppose to find the volume and surface area of a cylinder. What I'm trying to do is pass values from one class, to a second class, and that second class passes values to a third class.

This may be a clearer explanation: The first class is the main program which sends values to the second and third class. The second class is used do calculations for a circle (a pre-existing class from another assignment). The third class grabs the values that the second class calculated and calculates those values with the one that was passed from the first class to the third class. The first class then prints the outcome.

Problem is when the program gets to the third class, it just calculates the value from the first class with the default constructor from the second class. It's like the second class never received the values from the first class. I think I'm missing a step, but I don't what it is.

First Class:

package circle;
import java.util.Scanner;
public class CylinderInput
{
static Scanner in = new Scanner(System.in);
public static void main(String[] args)
{
//user defined variable

[Code]...

View Replies View Related







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