|
|
A type of coffee.
If you can find your way to CodeProject, then you should be able to find your way to Google, for such an elementary question. Or try your local library/bookstore.
|
|
|
|
|
I need to do a program with 2d array.
- it should ask the amount of columns and rows from the user
- print the array
- add numbers 1,2,3...
- print the array
- calculate every rows averige and print it after the row
- calculate every columns sum and print it after the column
Here is what i have (after two days )
import java.util.Scanner;
public class matrix {
private static Scanner scanner;
public static void main(String[] args) {
scanner = new Scanner(System.in);
System.out.println ("Create matrix AxB");
System.out.println ("Set rows (A)");
int A = Integer.parseInt(scanner.nextLine());
System.out.println("A = " + A);
System.out.println(" ");
System.out.print("Set columns (B)");
int B = Integer.parseInt(scanner.nextLine());
System.out.println("B = " + B);
System.out.println(" ");
int X = A * B;
int[][] matrix = new int[A][B];
for (int row=0; row<matrix.length; ++row)
for (int column=0; column<matrix[row].length; ++column) {
System.out.println("Set element "+row+", "+column);
matrix[row][column] = scanner.nextInt();
}
System.out.println("Your matrix:");
for (int row=0; row<matrix.length; ++row) {
for (int column=0; column<matrix[row].length; ++column)
System.out.print(matrix[row][column]+"\t");
System.out.println();
}
}
}
So Please someone help me
|
|
|
|
|
OK, that seems to work quite well, so all you need is to add the calculations of the averages and sums. You can do these as you print the rows and columns, althugh you will need an extra array for the column sums, and a variable for the averages. Something like:
int[][] matrix = new int[A][B];
int sums[] = new int[B];
int average;
for (int row=0; row<matrix.length; ++row)
for (int column=0; column<matrix[row].length; ++column) {
System.out.println("Set element "+row+", "+column);
matrix[row][column] = scanner.nextInt();
}
System.out.println("Your matrix:");
for (int row=0; row<matrix.length; ++row) {
average = 0;
for (int column=0; column<matrix[row].length; ++column) {
System.out.print(matrix[row][column]+"\t");
average += matrix[row][column];
sums[column] += matrix[row][column];
}
System.out.println("- average: " + (average / B));
}
for (int column=0; column<matrix[0].length; ++column) {
System.out.print("----\t");
}
System.out.println();
for (int column=0; column<matrix[0].length; ++column) {
System.out.print(sums[column]+"\t");
}
System.out.println();
}
You could also improve the accuracy of the averages by using a float type rather than integer.
|
|
|
|
|
Thank you very much Richard!!
|
|
|
|
|
|
Hi,
I am playing around with the idea of using hashing algorithms to store private data in the cloud. I recon it should be doable on most client platforms, because of the availability of hashing algorithms.
- Each blob of data will have its own unique salt associated.
- A password + salt is used to create a hash (only salt leaves the client).
- The hash is used to encode the data in a rather simple manner.
- The encoded data + salt + algorithm version is to be stored in the cloud.
The hash can be used to decode the encoded data again.
The algorith implementation is here: ARosettaStoneV1.java[^]
Here is a unit test: RosettaStoneV1Test.java[^]
As an example the unit test can produce:
quebird.brokenclouds.core.unit.stones.v1.RosettaStoneV1Test@37bba400.testEncodeAndDecode():
#0: MD5 + UTF-8 on 'Hello World! Hellø Wørld! 0123456789 §$!#€%&/()=?+´`¨^*'-_.:,;<>'
encode: --- START --- [algorithm=BC1+MD5]
encode: salt[length=36] = 49 52 102 50 53 99 102 101 45 48 50 101 56 45 52 50 53 97 45 97 48 52 50 45 100 98 50 98 50 52 100 97 49 51 57 53
encode: data[length=71] = 72 101 108 108 111 32 87 111 114 108 100 33 32 72 101 108 108 -61 -72 32 87 -61 -72 114 108 100 33 32 48 49 50 51 52 53 54 55 56 57 32 -62 -89 36 33 35 -30 -126 -84 37 38 47 40 41 61 63 43 -62 -76 96 -62 -88 94 42 39 45 95 46 58 44 59 60 62
encode: hash[length=16] = 37 5 88 33 -2 -28 58 -32 71 27 119 -120 22 -87 -91 -2
encode: padding[length=16] = 84 24 -28 -92 25 61 -97 -27 125 -98 71 -57 43 24 -98 100
encode: output[length=88] = 0 0 0 0 0 0 0 71 -87 79 10 -37 4 109 54 -115 -15 -121 106 109 -71 -60 106 -111 -88 82 -41 -104 -89 85 70 65 -38 127 49 -111 -77 16 -56 -14 -85 -94 81 -104 29 54 -8 88 43 63 35 89 -18 -114 58 90 48 -94 -52 57 35 59 116 74 -45 123 43 75 -5 -128 52 101 -95 52 -118 27 32 57 83 77 72 -1 123 -124 95 -110 51 120
encode: --- END --- [algorithm=BC1+MD5]
decode: --- START --- [algorithm=BC1+MD5]
decode: salt[length=36] = 49 52 102 50 53 99 102 101 45 48 50 101 56 45 52 50 53 97 45 97 48 52 50 45 100 98 50 98 50 52 100 97 49 51 57 53
decode: data[length=88] = 0 0 0 0 0 0 0 71 -87 79 10 -37 4 109 54 -115 -15 -121 106 109 -71 -60 106 -111 -88 82 -41 -104 -89 85 70 65 -38 127 49 -111 -77 16 -56 -14 -85 -94 81 -104 29 54 -8 88 43 63 35 89 -18 -114 58 90 48 -94 -52 57 35 59 116 74 -45 123 43 75 -5 -128 52 101 -95 52 -118 27 32 57 83 77 72 -1 123 -124 95 -110 51 120
decode: hash[length=16] = 37 5 88 33 -2 -28 58 -32 71 27 119 -120 22 -87 -91 -2
decode: output[length=71] = 72 101 108 108 111 32 87 111 114 108 100 33 32 72 101 108 108 -61 -72 32 87 -61 -72 114 108 100 33 32 48 49 50 51 52 53 54 55 56 57 32 -62 -89 36 33 35 -30 -126 -84 37 38 47 40 41 61 63 43 -62 -76 96 -62 -88 94 42 39 45 95 46 58 44 59 60 62
decode: --- END --- [algorithm=BC1+MD5]
I am by no means a crypto-guru, so I would appreciate any comments you might have on the idea, the algorithm, etc. References on the subject are also appreciated.
Kind Regards,
Keld Ølykke
|
|
|
|
|
import java.lang.*;
import java.awt.*;
import java.awt.event.*;
public class Post extends Frame
{
public Post()
{
this.addWindowListener(new MyWinAdap());
}
public void paint(Graphics g)
{
g.setColor(Color.black);
Dots d = new Dots();
Text t = new Text();
d.start();
t.start();
}
public static void main(String[] args)
{
Post dtd = new Post();
dtd.setTitle("Dots and Displaying text");
dtd.setSize(500,500);
dtd.setVisible(true);
}
}
class Dots extends Thread
{
public void run()
{
int x,y;
Graphics g;
for(;;)
{
x=(int)(Math.random() * 500);
y=(int)(Math.random() * 500);
g.drawLine(x,y,x,y);
try
{
Thread.sleep(20);
}
catch(Exception ex)
{
}
}
}
}
class Text extends Thread
{
public void run()
{
Graphics g;
g.drawString("Hello!",100,100);
}
}
class MyWinAdap extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
It gives an error - "variable g might not have been intialised".
I want two or more threads working on the same frame displaying different kind of data.
How can I do this??
Is there any solution to this??
I'm a beginner please guide me..
|
|
|
|
|
|
Graphics is a class. so we are creating an object for that class.g variable is not a problem.
create multiple threads and pass POST object to threads which extends FRAME class.
|
|
|
|
|
I installed the sun java application server and am have a big problem. After I installed the application a menu option folder "Sun Microsystems" was added to my All Programs. After the installation it seemed that all of the options were installed except for the actual application server. I ran the uninstall menu option and now the "Sun Microsystems" menu option folder is still on the All Programs list and except the main folder no menu items appear except for the sub folder "Application Server PE" and in it the contents display (empty). Also, after reading several posts it indicated I need several key values from the registry should be removed. After looking at the registry the options key value indicate (default), (value not set). Now when I go back and retry to install the application server again I receive the error "Could not find the required version of the java(TM) Runtime Environment.
I am really stuck and need help bad. Can someone help?
|
|
|
|
|
Install the Java Runtime as suggested by the error message. You may first need to ensure that everything related to both packages is removed from your system first. You also may get better support for the application server issue at the Oracle support forums.
|
|
|
|
|
I am getting the following exception while upgrading the axis2 version from 1.5.4 to 1.6.1.Note i am using OSGi 3.8.2,jetty server version 8.1.3
2015-09-04 19:21:42.250:WARN:oejs.ServletHandler:/services/WebServiceReceiver java.lang.RuntimeException: Undefined 'Security policy namespace cannot be null.' resource property at org.apache.rampart.RampartException.getMessage(RampartException.java:81) at org.apache.rampart.RampartException.(RampartException.java:41) at org.apache.rampart.RampartException.(RampartException.java:57) at org.apache.rampart.RampartMessageData.setWSSecurityVersions(RampartMessageData.java:373) at org.apache.rampart.RampartMessageData.(RampartMessageData.java:261) at org.apache.rampart.MessageBuilder.build(MessageBuilder.java:61) at org.apache.rampart.handler.RampartSender.invoke(RampartSender.java:65) at org.apache.axis2.engine.Phase.invokeHandler(Phase.java:340) at org.apache.axis2.engine.Phase.invoke(Phase.java:313) at org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:262) at org.apache.axis2.engine.AxisEngine.sendFault(AxisEngine.java:516) at org.apache.axis2.transport.http.AxisServlet.handleFault(AxisServlet.java:433) at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:216) at javax.servlet.http.HttpServlet.service(HttpServlet.java:755) at javax.servlet.http.HttpServlet.service(HttpServlet.java:848) at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:598) at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:486) at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1065) at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:413) at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:999) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:111) at org.eclipse.jetty.server.Server.handle(Server.java:350) at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:454) at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:900) at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:954) at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:851) at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235) at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:77) at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:606) at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:46) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:603) at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:538) at java.lang.Thread.run(Thread.java:744) [2015-09-04 19:21:42,292] 637744 [Thread-95] ERROR errors - ERROR:CONNECTOR:webserviceconnector:Attempted read on closed stream. [2015-09-04 19:21:42,294] 637746 [Thread-95] ERROR errors - CONNECTOR:webserviceconnector:webservice:Attempted read on closed stream.
Rohit
|
|
|
|
|
This is not a Java programming issue. You should go to the axis2 website for help.
|
|
|
|
|
I need assistant in developing java application student's result transcript
|
|
|
|
|
|
book examples of procedure stored for sqlserver
|
|
|
|
|
|
|
Hello,
I am wondering if following methods in my script are vulnerable for DOM XSS attack? If yes, what is the best practice to write them. Kindly help if you can guide about it.
1. document.createElement()
2. document.getElementsByTagName()
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
Thank you for your time.
Best Regards,
Supriya
|
|
|
|
|
|
I am really sorry for that. Thank you for the correct group link.
Best Regards,
Supriya
|
|
|
|
|
Hi,
I have to learn java quickly in real time .
currently i'm not have that much tough in jav platform please advice how to learn
my email address cutesam.mca@gmail.com
|
|
|
|
|
|
Is anyone doing Mutation Testing?
It is something I recently discovered and Java has a great tool for it called PIT. I honestly feel it is one of the greatest things since sliced bread but no one seems to really be doing it. The concept has been around since '71 so I am really wondering why it has taken so long to catch on.
|
|
|
|