Java | JSP | JSF Answers

Questions: 4 418

Answers by our Experts: 3 943

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search & Filtering

Write a java program. User enters size of a triangle from 1-50. Print the triangle in asterisks. The user's input is the middle of the triangle. For example, if the input is 3, the triangle will look like this:
*
**
***
**
*
You have to use nested for loops. So far i did the top half of the triangle:

for(row = 1; row <= size; row++)
{
for(col = 1 ; col <= row ; col++)
{
System.out.print("*");
}
System.out.println();
}
Now i have to do the bottom half and do not know how.
I have to write a program so the user can input the size of a triangle, 1-50, and then output the triangle with asterisks. The user's input is the middle of the triangle. For example, if they input 3, it looks like this:
*
**
***
**
*
I need to use nested for loops. So far i did the for loop for the top of the triangle:
for(row = 1; row <= size; row++)
{
for(col = 1 ; col <= row ; col++)
{
System.out.print("*");
}
System.out.println();
}
Now i need to do the for loop for the bottom half and cannot figure it out.
I am doing a program and I cant seem to make the loop work to find the total payment on a loan plus the interest.
Hi there,

I need to run this code in bluej java but, it wont allow me to. There are no syntax errors and basically im trying to encrypt a java file called "MyFriends.txt". Please help me out as its quite urgent. Below is my code thanks!

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;

public class FileEncrypt
{
public static void main(String[] args) throws Exception
{
byte[] plainData;
byte[] encryptedData;
KeyGenerator keygen = KeyGenerator.getInstance("DES");
SecretKey key = keygen.generateKey();
Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, key);

File f = new File("input.txt");
FileInputStream in = new FileInputStream("MyFriends.txt");
plainData = new byte[(int)f.length()];
in.read(plainData);

encryptedData = cipher.doFinal(plainData);

FileOutputStream target = new FileOutputStream(new File("encrypted.txt"));
target.write(encryptedData);
target.close();






}
}
What is the java code to make one word italicized in a sentence?

For example, print the sentence "I like the color yellow" and italicize the word color.
I need to create a file in java. However there's errors in my output. Could you please help me out?
import java.io.*;
/**
* Write a description of class CreateFile1 here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class CreateFile1
{
public static void main(String[] args)throws IOException
{
File f;
f=new File("C:\MyFile.txt");
if(!f.exists()){
f.createNewFile();
System.out.println("New file"+ "C:\MyFile.txt"+" has been created to the current directory");
}
}
}
Assume the variable below are declared and initialized as shown:
int n,m;
double x,y;
n=23; m=5; x=2.3; y=4.5

what is the value of each expression below?
1. n/m 2. n%m 3. 25%m 4. m/n 5. n-x * 2 6. y-x+m 7. (double)n/m
Write the complete Java statement.

Request that the user enter the radius of a circle from the keyboard and store the value entered in the double variable, radius.
Assign to the variable float variable totalCost the product of the int quantity times the double cost.
Write the complete java statement.
What type of the event listeners handles the mouse movement?
LATEST TUTORIALS
APPROVED BY CLIENTS