import java.util.Scanner;
public class Magic
{
public static void main ( String args[] )
{
Scanner in = new Scanner (System.in);
int[][] square = new int [4][4];
int sqlength = square.length;
int magicValue = sqlength * (sqlength * sqlength + 1) / 2;
[Code] ....
Here is what the output should look like.
Please enter the 4 values for row 0, separated by spaces: 1 2 3 4
Please enter the 4 values for row 1, separated by spaces: 5 6 7 8
Please enter the 4 values for row 2, separated by spaces: 9 10 11 12
Please enter the 4 values for row 3, separated by spaces: 13 14 15 16
I have had to create a text analyser. I have created the program but it is all within the main method. The specification states that I have to have at least two methods within my Program.
import java.io.*; import java.text.SimpleDateFormat; import java.util.*; import javax.swing.*; import javax.swing.filechooser.FileNameExtensionFilter; public class Analyser { public static void main(String[] args) throws FileNotFoundException, UnsupportedEncodingException {
So I want the method getDisplayText of d to be returned as long as the for loop runs. When I do this I get a compile time error to enter a return statement. I am currently trying to fix it by returning an empty string, yet this doesn't seem the right way to go.
public static String displayMultiple(Displayable d, int count) { for(int i = 1; i <= count; i++) return d.getDisplayText(); return ""; }
I am working with a program I wrote for class. I got it to compile and do what I want, But I was wondering how I can format my methods to to display a decimal with 1-2 decimal places. Would I create a method in my NumberAnalysis class to do it for me? Or would I declare an instance of the DecimalFormat class in my main method?
import java.util.Scanner; //Needed for Scanner Class import java.io.*; //Need for File and IOException import java.text.DecimalFormat; public class Ex8_11 { public static void main(String[] args) throws IOException{ { DecimalFormat decformatter = new DecimalFormat("#0.00");
[Code] .....
This is my output:
Lowest Number: 1.09 Highest Number: 82.76 Total Number: 367.89000000000004 Total Average Number: 30.657500000000002
Think I just solved the answer to my own question, I did it by declaring double variables in my main method and called the methods and instantiated the variables into the methods... Is there a better way to do this?
package lesson4.skowronek; import java.util.Scanner; //Needed for Scanner Class import java.io.*; //Need for File and IOException import java.text.DecimalFormat; public class Ex8_11 { public static void main(String[] args) throws IOException{
I am trying to write a java code for a homework problem in my intro java class but im having problems. This is the problem:
Write a program that open the MyFile.txt and read from a file with these criteria.
1)-The program should display the first five lines of the file’s contents only.
2)-If the file contains less than five lines, it should display the file’s entire content. You must check for end of file and less than 6 lines on the loop iterations.
3)- your program should use loop to read the line by line of the file MyFile.txt.
The serperate myfile.txt has this
I can still remember, at the end of that year, we sat for the last time in our circle together. She played us her favorite song, "like a bridge over troubled water" and quietly passed out a gift she had made for each of us.She had made each of us a pottery heart with our name and the date on it on the back each read "I believe in ME".We all cried including her. She told us she would always remember US. We believed she would.
and this is what the code is suppose to look like after you run it : Java33.png
And this is what i have so far : Java22.png
what needs to go next to complete the javascript to show the first 5 lines of the text files?
I'm currently working on a program that is supposed to translate morse code and then display the result and I'm stuck, my program has tons of errors when I try to compile.
public class Assignment10 { public static void main ( String [] args ) { String str = Input.getString("Please type in a word"); char [] letters = {'a','b','c','d','e','f','g',
I written java code in JSP to display data. I know it is bad practice. Actually my Business-service communicates with DB and returning data in the form of MAP. I don't have beans Because the fields in DB is dynamically changing. So, for now I'm retrieving Data by writing Java code in JSP. Is there any other way to display data without writing java code in JSP?
in my ui i will i will select enabled or disabled then it will go in controller , i already debug it and it goes on the right controller based on what i select on ui my problem is when i select disabled it dont display the message but when i select enabled it displays the message, then i check the databases status is change based on what i select but when i change into disabled doesnt display any message.if select enabled will go in controller then change status into true then update the status then will see the message in ui
Write a program that will read two numbers and an integer code from the keyboard. The value of the integer code should 1, 2, 3, 4. If the value of the code is 1, compute the sum of the two numbers. If the code is 2, compute the difference (first number minus second). If the code is 3, compute the product of the two numbers. If the code is 4, and the second number is zero, compute the quotient (first divided by second). If the code is not equal to 1,2,3,4, display an error message. The program is then to display two numbers, the integer code and the computed result to the screen
here is the code that I have so far:
public static void main(String[] args) { Scanner read = new Scanner (System.in); int num1, num2, code, sum; System.out.println("Please enter a number"); num1 = read.nextInt();
How i would convert this java code to display using the printf statement, with two decimal places to the right...here is the source code so far, but it has a few errors and needs to be reformated for printf
import java.util.Scanner; // scanner class public class PROB3_CHAL15 { public static void main(String[] args) { double checks =0, totalfee =0, fee = 10, fee1 =.1, fee2 = .08, fee3 = .06, fee4 = .04, checkFee; String input; Scanner keyboard = new Scanner(System.in);
I have been creating a Java program to track inventory using an array. I need to add a search function to it to take a term, input through a text field, and locate a matching instance within the array. How can I code a JButton to grab test input from a JTextField and search for it within the array then display the corresponding information? I also need to add buttons to add and delete items as well.
I am trying to write a program that will generate a QR Code from an input text and also display some information about the input/output bits. So far I have created the frame and what to do next. And I'm not sure if I am on the right track since my level of programming is not that great. By the way, I am using zxing libraries from GitHub. I know, there are plenty of generators online for the QR Code, but that is not what I am looking for. As you can see on the attached image, I am more interested in the efficiency of encoding 2D data. Also, I noticed that almost all the online projects regarding 2D codes are for Android. Which is not very useful.
My project in eclipse..I get the error below when I run MyTagUser.jsp -
HTTP Status 500 - /jsp/MyTagUser.jsp(14,0) Attribute subTitle invalid for tag Header according to TLD org.apache.jasper.JasperException: /jsp/MyTagUser.jsp(14,0) Attribute subTitle invalid for tag Header according to TLD org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40) org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)...et
<html> <body> <!-- Here I am going to use scripting like scriptlet,expression and other element like jsp declaration element --> <%!int i=0;%> <%System.out.println("Scriptlet");%> <%=new String("Expression")%> </body> </html>
import java.util.HashSet; import java.util.ArrayList; public class Graph { double [] [] adj; graph (double [] [] a) { adj= new double [a.length][a.length]; for (int i=0;i<a.length;i++) for (int j=0;j<a.length;j++) adj[i][j]=a[i][j]; }
C:UserscDesktopGraph.java:: error: invalid method declaration; return type required graph (double [] [] a)
My code runs correctly when i run the clients one after another without using threads.I am getting this following error when i run my multi-threaded server. When a server accepts a client connection, ClientHandler is the thread that handles that client.Exception in thread "main"
java.io.StreamCorruptedException: invalid stream header at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:737) at java.io.ObjectInputStream.<init>(ObjectInputStream.java:253) at comm.DOMTransfer.<init>(DOMTransfer.java:25) at ClientHandler.<init>(ClientHandler.java:18) at GridInfo.main(GridInfo.java:34)This is where the error occurs:input = new ObjectInputStream(socket.getInputStream());
import java.io.*; public class MagicSquare { public static void main(String[]args)throws IOException { BufferedReader in=new BufferedReader (new InputStreamReader(System.in)); System.out.print("Enter a Magic Number: "); int number=Integer.parseInt(in.readLine());
[Code] ....
//where should i enter a even number that will be outputted "invalid" //and it only should accept odd numbers
While doing trial and error got caught in the below scenario.
public class Crypt { public static void main (String args[]) { /*all I want is calculate a binary number (ex -: 22 , 34) using decimal base (10n). *So, I have to convert 2 p into 10n form so I have to find n in terms of p . We have x as the input. * The formula works as below. *2p =10n *p ln (2) =n ln (10) *n = p [ln(2) / ln(10)] *2 p = 10 p [ln(2) / ln(10)]
So today i was trying to compile a simple script that used to work before on Sublime Text 2, an i got the following error;
javac: invalid flag: Usage: javac <options> <source files> use -help for a list of possible options
I already know the script works because i didn't change anything since the last time it work, but anyways just in case i tried running a HelloWorld program just to check it out and i got the same error. The i stop trying to compiling the HelloWorld on Sublime so I went to Terminal and i got the same exact error.
I'm trying to establish an SSL connection (using a self-signed certificate). However, I can't seem to get the handshake to work. At the moment server side, I've created the public/private key + signed certificate and then stored them in a KeyStore. I've also stored this signed certificate in a KeyStore (trustStore) client side, so it can compare.
I have now slowly moving on the learning Database Connectivity.Found a simple example on one site and tried to execute it, Creating a database, connecting to it and displaying the output.
I am getting trouble with recordset in displaying all the records in the badabase. It displays the very first record correctly but if I try to enclose it in while(rs.next()) loop, it generates an error message saying "Invalid operation at current cursor position".
Make a password rule, and take input of the password from the user and compare the password with your rule, if the user had entered valid password then print the message, password valid, else the password is invalid for (the whatever) reason.
Rules:- -Length 8-12 -Should have one numeric character -No Special Character -Atleast one UPPERCASE letter
PHP Code:
import java.util.*; import java.lang.String; import java.lang.Character; public class PasswordSpence { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Please enter a Password: "); String password = input.next(); if (isValid(password)) {