Write A Program That Reverses A List Of 15 Integers Preferably In Place
Nov 24, 2014Write a program that reverses a list of 15 integers preferably in place.
View RepliesWrite a program that reverses a list of 15 integers preferably in place.
View RepliesEx. If I type 5943, the program will say
mill = 5
hun = 9
ten = 4
uni = 3
get the picture I had to translate the decimal value names from a different language.
This is what I have tried...,
Java Code:
import java.util.Scanner;//Permite el uso de leer el teclado del usuario
public class DeterminarValorDecimal//Nombra el documento
{
public static void main(String [] args)//Podemos ver la clase
{
[Code].....
But what this does is I have to enter the single digits one by one. I want to be able to type the whole number. Is there a method that reads the length of the whole number and lets me classify each digit so I can do what I want to do?
Design, write a java program to input 7 integers and, for each integer, calculate and display its square and cube.
View Replies View RelatedProject is due before midnight eastern time (3 more hours). I have been working on this all day, we have not learned arrays or anything and just started 'for' loops. I don't really know how to implement that system yet. However, he wants us to check all the possible handwritten math ways of doing this. I have tried but I cannot return my numbers beside the card.my program only prints the type and I still have more cases to add as well..
QUESTION: Write a Java program that reads 5 integers, each of which is in the range of 1 and 13 representing a simplified poker card with no suit. Your program should then print the ranking of the hand with card number(s) beside the ranking. The rankings to determine are Four of a Kind(4 of the 5 cards of the same rank), Full House(3 of the 5 cards of the same rank, and 2 cards of another rank), Straight(5 cards of sequential rank), Three of a Kind(only 3 cards of the same rank), Two Pair(2 cards of the same rank, 2 cards of another rank, and no card of either rank), One Pair(only 2 of 5 cards are of the same rank), and High Card(no two cards of the same rank). Some sample runs are:
input: 2, 3, 2, 2, 2; output: Four of a Kind(2)
input: 2, 3, 2, 3, 2; output: Full House(2, 3)
input: 2, 3, 4, 5, 1; output: Straight(5)
input: 1, 13, 11, 10, 12; output: Straight(1)
[code]....
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]....
I need to round my variables to the nearest "tens" place and I'm having trouble doing so. Every time I run the program it comes back with a number ending in .0 even if its something like 11 / 3. How can I fix this?
public static void results(int game, int totalGuess, int best) {
double avg = Math.round((totalGuess / game) * 10.0) / 10.0;
I am trying to write a java program that asks the user for a list of names (one per line) until the user enters a blank line. At that point the program should print out the list of names entered, where each name is listed only once (i.e., uniquely) no matter how many times the user entered the name in the program. I am supposed to use an ArrayList for this problem.
My idea for a solution is to create an ArrayList<String>, read each name, i.e., line, entered and then to see if that name is already in the ArrayList. I created a for loop to check each element in the ArrayList but when I try to assign an element to a string variable I get the error "Type mismatch: cannot convert from Object to String". Not sure why that is happening because the ArrayList is defined as a String list.
Here is the code so far.
/*
* File: UniqueNames.java
*/
import acm.program.*;
import java.util.*;
[Code].....
Write a java program to store employee information in a linked list, the program should implement the following functions:
The program should display the list of functions, and ask the user to enter the number of function that he/she wants to do, then perform the function as it is required in the previous table.
import java.util.*;
public class Employee {
Scanner in = new Scanner(System.in);
String Name;
String Address;
String Department;
int ID;
int Salary;
[code]....
this is my out put
Please choose a number:
1-Add a new employee
2-Update employee's info
3-Remove employee's info
4-Exit
1
Enter name:
Enter address:
2
Enter department:
3
Enter ID:
4
Enter salary:
now:
1- why are not my adding coming out in the output only the Enter name & Enter address ??
2- how can I add names and ID's and information to test that program
Write an application that reads five integers, determines and prints the largest and smallest integers in the group. Use only the programming techniques you learned in this chapter. (which means: use only if statements and the equality and relational operators).If I want to solve this I will write nested if statements for every probability like the following.The probability: the first integer is the largest and the fifth integer is the smallest:
1>2>3>4>5
1>2>4>3>5
1>4>3>2>5
1>4>2>3>5
1>3>4>2>5
1>3>2>4>5
And so on for every probability.
Trying to read integers from a text file and place them in a linked list in order. Program is compiling and running fine, just not the way I am intending when I am calling the methods. (Note: You have to enter the file location in the var x if you plan on running this.)
import java.io.*;
import java.util.*;
public class Node {
public int value;
public Node next;
Node(int x) {
this.value = x;
[code]....
I'm having trouble formatting my output and issues with the decimal places. Here's my code:
import java.util.Scanner;
import java.text.DecimalFormat; // Imports DecimalFormat class for one way to round
public class lab3 {
public static void main(String[] args) {
String heading1 = "Hour", heading2 = "Distance Traveled";
int timeElapsed, hour, speed;
[Code] ....
And here's my output (Click on the image since it's pretty small):
javaIssues.png
Issue:
1) The Hours 2 and 3 aren't aligned to 1.
2) The 80 and 120 in Distance Traveled have 6 decimal places when it should not have decimals.
I've got a very simple java program (J.java, see below) on my application server that successfully connects to an Oracle 11.2 database on a database server (both servers are Linux CentOS) using JDBC thin driver from Oracle.
As you can see from the setURL command in the Java code below, I've configured the application and database servers to sit next to each other, and they're on the same network (cross-cable connected to each other), so there's no network traffic on these (development) boxes except my code.
The problem is the execution time varies a lot. If I run it 5 times, it (seemingly randomly) could take 0.01 seconds, or 10 seconds, or 50 seconds, or over a minute to execute. If it takes over a minute (roughly), the program doesn't complete, but the error shown below is returned instead.
------error returned when execution take more than about 1 minute-------
gf@host9 [~/dbwork]# java -cp ./ojdbc6_g.jar:. J
Exception in thread "main" java.sql.SQLRecoverableException: IO Error: Connection reset
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:494)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:547)
[Code] ....
----------the java code for: J.java-------
// To compile: # javac -cp ./ojdbc6_g.jar:. J.java
// To run: # java -cp ./ojdbc6_g.jar:. J
import java.sql.*;
import oracle.jdbc.*;
import oracle.jdbc.pool.OracleDataSource;
class J {
public static void main(String args[]) throws SQLException {
[Code] ....
Write a method maxOccurrences that accepts a list of integers as a parameter and returns the number of times the most frequently occurring integer (the “mode”) occurs in the list. Solve this problem using a map as auxiliary storage.
If the list is empty, return 0.
Main:
package shoppingcartselection;
import javax.swing.*;
import java.util.ArrayList;
public class Main
{
public static void main(String[] args)
{
ArrayList<Item> items = new ArrayList<>();
[Code] .....
I have it to save to a text file the subtotal, sales tax, and the total cost of all items in the cart after clicking on Checkout. I need it to also show the Items that where in the cart, along with how much each Item costs. I've tried this:
public void save(ArrayList Receipt) throws FileNotFoundException
{
PrintWriter pw = new PrintWriter(new FileOutputStream("Receipt.txt"));
for (Item itemsInCartNames : itemsInCart)
pw.println(itemsInCartNames);
pw.close();
}
But this is what gets saved to the Receipt.txt file:
shoppingcartselection.Item@16752c9
itemPices.txt:
Magic Booster Pack, 4
Magic Fat Pack, 40
Magic Intro Deck, 12
Magic Duel Deck, 20
Magic Card Sleeves, 8
Magic Play Mat, 25
Magic Booster Box, 120
Dice Pack, 6
Video Game, 60
Book, 10
Candy, 1
Soda, 1
Lunch, 10
Water, 1
Shirt, 10
Hat, 5
Game Console, 400
Desktop, 800
Laptop, 1000
For the latest assignment, my instructor has asked us to create a program where we create lines of at least for integers and if the program registers there being four of the same integer horizontally, vertically, or diagonally it returns true. For example:
1 1 1 1 1 2 3 4 1 2 3 4
4 3 6 2 2 1 4 5 1 5 6 7
8 2 0 3 3 2 1 6 1 3 5 7
4 7 9 3 5 7 4 1 1 8 9 0
If the program doesn't see four integers of the same value anywhere, it is supposed to return false. I've got it so it returns true for the lines above, 6x6 lines of integers and lines where only four out of six+ integers are equal. However, I cannot get my code to return false if there are only three matching integers in a row/column/diagonal nor can I get the program to print out either true or false for lines that do not start at the top left corner. (i.e 2 3 1 1 1 1) For the former I get this error message:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
at ConnectFour.is4Consecutive(ConnectFour.java:41)
at ConnectFour.main(ConnectFour.java:32)
For the latter:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 6
at ConnectFour.is4Consecutive(ConnectFour.java:43)
at ConnectFour.main(ConnectFour.java:34)
The answer to fixing my code is probably something small or something that will make me wonder why I hadn't thought of it myself... Here is my code:
import java.util.Scanner;
public class ConnectFour {
private static Scanner sc;
public static void main(String[] args)
{
sc = new Scanner(System.in);
System.out.print("Enter the height: ");
int h = sc.nextInt();
System.out.print("Enter the width: ");
[Code] .....
1 1 1 1
4 3 6 2
8 2 0 3
4 7 9 3
1 2 3 4
2 1 4 5
3 2 1 6
5 7 4 1
1 2 3 4
1 5 6 7
1 3 5 7
1 8 9 0
I'm required to create a program that finds the minimum value in an Array of integers.
Here is my approach :
public class Person {
public static void main(String [ ] args){
int theArray[]=new int [10];
int result = 0;
for (int i:theArray){
if (i < Integer.MAX_VALUE)
[Code]...
I can't really progress from this position. I keep getting told to change the return type to int on main method, then when i do it says change it to void..
Here is a simple program on applets that is giving me a bit of headache since it cannot always display the two numbers that it is supposed to: the largest and smallest of the five input integers.....I cannot see where i went wrong, you can always create separately the HTML file to load the applet in an appletviewer of your won size.
*
23.6 (Largest and Smallest) Write an applet that reads five integers, determines which are the largest and smallest integers in the group and prints them. Draw the results on the applet.
*/
import java.awt.Graphics;
import javax.swing.JApplet;
import javax.swing.JOptionPane;
[Code] .....
I'm playing with vectors for the first time... What I'm trying to do is to allow a user to input one or more integers and store them in a vector for manipulation later on in the program... Here's the portion of the program I'm working with:
Java Code:
package com.itse2317;
import java.util.*;
public class VectorTest
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
[code]...
My question is this: Is there any way to move from inputting integers to printing them, without entering a non-integer (for example, hitting enter)? I looked at the API for the Vector class, and either I'm not thinking about the problem the right way to be able to find an answer, or it's just not there.
How do i write a program using textEdit? I can't even get the examples to open?
View Replies View RelatedMy program successfully reads a file, reports back what it finds and creates an output file. However, I cannot get it to write to the output file, it is always blank!
Here's my code:
import java.util.Scanner;
import java.io.*;
public class Ex19
{
public static void main (String [] args)
{
//Variables
[code]....
I have to write a program that find the sum of two numbers 62 and 99 and stores them in a variable named total. However, I have one error that I just can't get rid of and can't tell what it is. I'm using jGrasp and here's what it says:
Programming Challenge #5.java:14: error: class SumofTwoNumbs is public, should be declared in a file named SumofTwoNumbs.java
public class SumofTwoNumbs {
^
1 error
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
and here: is my code:
import java.util.Scanner;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
// This program has variable of several of the integer types.
public class SumofTwoNumbs {
public static void main(String[] args) {
[code]....
Write a program called GeometricMean that prompts the user to
1.Enter the number of values (total number of instances) that should be processed
2.A set of values to be processed (in a while loop)and then calculate the geometric mean of the values entered. You should use a while loop to perform the multiplication part of the calculating the geometric mean. The program should output the initial data and the labeled geometric mean. Consider printf, and DecimalFormat.
My Program:
import java.util.Scanner;
public class GeometricMean{
public static void main(String[] args) {
Scanner keyboard= new Scanner(System.in);
[code]...
Write a java program that uses a While loop and persistent output to count down from 33 to 0 by threes, and put each value on a separate line, also do this in for loop.
View Replies View RelatedHow to Write Program with out using control structures
IMG_4216.JPG
I'm trying to use graphics for my programs and here I'm trying to write a program that searches through files for text received from a JTextField. However, it does not seem to be working as my message is not displayed when text is found...
I used applet. Here are the functions:
JTextField jtf;
JFrame jf;
public void init()
[Code].....
I'm rather new to programming and I'm trying to make a gui program that will allow the user to create text files. They will be prompted to enter what they'd like to save their file as and then they will be allowed to input text to that file . They will also be allowed to open their files to modify or view its contents. So to start things off, I'm making a prototype if you will.. I've been able to save to a file the problem occurs when I try to read/display it.
Main Class:
public class MainActivity {
public static void main(String[] args) {
// Access to other classes
WriteFile writer = new WriteFile();
ReadFile reader = new ReadFile();
[Code] ....