|
Try changing your approach to the problem. Let's try this.
Input : 2, 4, 3
Desired output:
*
**
***
***
For graphical purposes let me remake the output as follows
*OO
**O
***
***
Replace the "O" with spaces. Does it help?
-chronodekar
|
|
|
|
|
How exactly does that help?
|
|
|
|
|
There might be a more efficient way of doing it, but here's my thinking.
1. Arrange all the numbers in descending order. Make note of the largest one ( = A). Also store the numbers in an array ( = ARRAY)
2. Count the number of inputs ( = B).
3. Visualize the output in the form of a rectangle - you need to draw (with ASCII) a rectangle whose height is A and width B. Alternatively, you need to print A no. of lines with B characters.
Now we come to implementation. In pseudo-code;
for (i = A ; i>0; i--)
{
for (j = 0; j<B; j++)
{
if (ARRAY(j) > i)
print("*");
else
print("O");
}
print("\n");
}
I think that should do it. Any edge case I missed?
-chronodekar
|
|
|
|
|
If I understand you post your 'algorithm' is incorrect.
You do not print vertically - Instead you print horizontally.
Hopefully you have already learned about loops and arrays. So
1. Put the values in an array
2. Write a method that finds the maximum value in the array. When if finds it set the array location to -1 (this is how you 'remove' it.)
3. Write a method that takes a X value and prints that many stars.
4. Put 2 and 3 together to print all the rows.
5. Think about how you know it will end (the '-1' is a hint.)
|
|
|
|
|
yeah i have read about loops and array.i can also find the max among all the elements of an array but what are you saying about location and all couldn't understand...
|
|
|
|
|
Hi
This is suman.
we are using spring with Hibernate in to my application,but we want to implenting jasyptHibernateEncryptorin in to my application.
its working fine when storing a new entry into database table and fetching the same entry,
but problem here its how to encrypt my old data.
can you please any one help me , ASAP
|
|
|
|
|
Hi,
Is there any way to read the current time zone of the operating system? I need to check it to see if it has been updated.
I have to do this every minute, without restarting the application and without launching an external process.
Thank you very much for your attention.
|
|
|
|
|
Try the following:
TimeZone tz = Calendar.getInstance().getTimeZone();
System.out.println(tz.getDisplayName());
System.out.println(tz.getID());
Note that an application can set its own time zone, independently of the system.
Veni, vidi, abiit domum
|
|
|
|
|
Thank you Richard. But try this and you will see what I mean:
TimeZone tz = Calendar.getInstance().getTimeZone();
System.out.println(tz.getDisplayName());
System.out.println(tz.getID());
tz = Calendar.getInstance().getTimeZone();
System.out.println(tz.getDisplayName());
System.out.println(tz.getID());
The time zone is set at the beginning of the current JVM process. It is subsequently detached from the system time zone and it sadly seems that there is no orthodox way to reattach it...
Bogdan Rechi.
|
|
|
|
|
The timezone setting is part of the environment of every process and is set at the time the process is started. I cannot see any way to tell when it changes apart from some system process that can hook into the operating system in some way. Sorry.
Veni, vidi, abiit domum
|
|
|
|
|
From the other responses....
Windows has the following command line utility
tzutil.exe
It has an option '/g' which returns the current timezone.
You use java.lang.Process to run it and collect the results.
|
|
|
|
|
Just note that a process inherits the environment from its parent process - and when the time zone is part of the environment, then tzutil will report the time zone of the application it was started from, which may be different from the time zone of the system.
|
|
|
|
|
Bernhard Hiller wrote: Just note that a process inherits the environment from its parent process
I just tried the following
- Open a console window
- Run tzutil to report current TZ
- Leave console window running.
- Change the TZ using the tray applet
- In the same console window above use tzutil again
- It reports the new TZ.
The documentation also states that tzutil updates the TZ in the registry. Which wouldn't be an environment update. So that suggests that in terms of reporting it would report from the same source and not from the environment.
|
|
|
|
|
Thanks for that information.
|
|
|
|
|
Unfortunately that only works for a new execution of a program, e.g. tzutil. I just tried it with a running Java application, and the app did not see the change of timezone.
Veni, vidi, abiit domum
|
|
|
|
|
Not exactly sure what you mean.
My suggestion was that one needs to run tzutil from the java application via Process. One would need to run it each time one wanted an update.
You tried that and it didn't work?
|
|
|
|
|
jschell wrote: My suggestion was that one needs to run tzutil from the java application via Process. And it works as you described.
Veni, vidi, abiit domum
|
|
|
|
|
Hi, I have a code that just won't work and I can't figure out why.
It's supposed to go to a survey page and fill in radio buttons randomly. For instance a survey with 100 questions, 6 per question. It fills in one question. For some reason my Aunt really needs this? Any thought?
function randomFromTo(from, to) {
return Math.floor(Math.random() * to) + from;
}
function autoFill() {
var radioList = [];
for (var i = 0; i < document.forms.length; i++) {
for (j = 0; j < document.forms[i].length; j++) {
if (document.forms[i].elements[j].type == "radio") {
if(typeof radioList[document.forms[i].elements[j].name.substring(0, 10)] == 'undefined') {
radioList[document.forms[i].elements[j].name.substring(0, 10)] = [];
}
radioList[document.forms[i].elements[j].name.substring(0, 10)].push(document.forms[i].elements[j].id);
}
}
}
for (var radio in radioList) {
var rand = randomFromTo(0, radioList[radio].length-1);
document.getElementById(radioList[radio][rand]).checked = true;
}
}
window.onload = function(){
autoFill();
};
|
|
|
|
|
This is the Java forum, but your code looks like Javascript to me.
Veni, vidi, abiit domum
|
|
|
|
|
what is the database for a sudoku game??
|
|
|
|
|
|
Right now with this code showing label inside the text box
I want to use the content pane for giving space in between then .
void InboundCheque()
{
printbtn.setVisible(false);
SpringLayout groupL = new SpringLayout();
Inbound.setLayout(groupL);
Inbound.add(chqlbl);
Inbound.add(chqstartingdate);
}
|
|
|
|
|
I'm developing a multiplatform systems peer to peer LAN Mesengger, here I have a problem to save the chat history and message broadcast. please tell me the solution about it?
thank you
|
|
|
|
|
Member 10567150 wrote: I have a problem to save the chat history and message broadcast. please tell me the solution about it? Unless you explain your problem in clear detail it is not possible to offer you a solution.
Veni, vidi, abiit domum
|
|
|
|
|
previously would reply thanks for my question, I am a graduate student, I'm writing his thesis entitled S1 multiplatform peer to peer lan messenger is where I was required to have 4 service features such as chat rooms, chat one by one, file transmission and broadcast messages, I 've membat 2 yes it features transmission pembinbing files and chat and I require the charge in my sekripsi no chat history nah I confused on the chat history and implementing the broadcast message and what difference it makes chat rooms and chat one by one? thanks for willing to help
|
|
|
|